[concurrency-interest] DCL clarification Immutable singelton

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Apr 9 14:23:35 EDT 2014


+1.

See also:
 http://hg.openjdk.java.net/code-tools/jcstress/file/tip/tests-custom/src/main/java/org/openjdk/jcstress/tests/singletons

What Hans is saying is here:
 http://hg.openjdk.java.net/code-tools/jcstress/file/tip/tests-custom/src/main/java/org/openjdk/jcstress/tests/singletons/UnsafeLocalDCLSingletonTest.java

-Aleksey.

On 04/09/2014 09:44 PM, Hans Boehm wrote:
> This code is wrong as written, for a different reason, unless _instance
> is volatile.  The two reads of _instance in getInstance() can be
> performed out of order and getInstance() can return null if another
> thread initializes it concurrently.  If you really need to do this,
> there should be exactly one read of _instance outslde the critical
> section. If this code is not so performance critical that you absolutely
> need to do this, don't, and use the volatile declaration.  The next
> person changing your code may also miss problems like this, and it may
> take years to track down the resulting intermittent problem.
> 
> Hans
> 
> 
> On Wed, Apr 9, 2014 at 6:49 AM, vikas <vikas.vksingh at gmail.com
> <mailto:vikas.vksingh at gmail.com>> wrote:
> 
>     Thanks guys very much for clarification.
> 
> 
> 
>     --
>     View this message in context:
>     http://jsr166-concurrency.10961.n7.nabble.com/DCL-clarification-Immutable-singelton-tp10862p10868.html
>     Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
>     _______________________________________________
>     Concurrency-interest mailing list
>     Concurrency-interest at cs.oswego.edu
>     <mailto:Concurrency-interest at cs.oswego.edu>
>     http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> 
> 
> 
> 
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> 



More information about the Concurrency-interest mailing list