#150 detect double checked locking

release_3.1
closed
Lars Kühne
Check (274)
5
2014-08-06
2003-03-25
Lars Kühne
No

the double checked locking idiom is a common error that
causes problems which are hard to detect by testing.

See
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
for a more in depth explanation.

DCL can be detected by searchin for a test (often
"something == null") within a synchronization block
within the same test

Example:

if ( s_singleton == null )
{
  synchronized( Singleton.class )
  {
        if ( s_singleton == null )
       {
             s_singleton = new Singleton();
       }
  }

}

Maybe there are other more sophisticated cases of DCL
(especially the "workarounds" mentioned in the link
above), those might not be detected - that is OK, it's
better than to raise false alarms.

Discussion

  • Lars Kühne
    Lars Kühne
    2003-03-29

    Logged In: YES
    user_id=401384

    done, including unit tests and docs

    this check will be included in release 3.1