Low-Lock Singletons In D

David Nadlinger see at klickverbot.at
Tue May 7 07:33:13 PDT 2013


On Tuesday, 7 May 2013 at 06:50:16 UTC, Mehrdad wrote:
> As far as I can see, there shouldn't be a need for any other 
> handshake in this example.
>
> As long as the object is fully initialized before _static is 
> written to (easy enough with just a memory barrier), there is 
> no penalty for subsequent reads whatsoever.
>
> Right?

The issue is that the write to _static might never appear on the 
other threads, thus leading to multiple instances being created - 
even though it is atomic in the sense that you never end up 
reading a pointer with e.g. only half of the bytes updated.

David


More information about the Digitalmars-d mailing list