[concurrency-interest] DCL clarification Immutable singelton
boehm at acm.org
Wed Apr 9 13:44:49 EDT 2014
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
On Wed, Apr 9, 2014 at 6:49 AM, vikas <vikas.vksingh at gmail.com> wrote:
> Thanks guys very much for clarification.
> View this message in context:
> Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest