Double Checked Locking

Andrew Wiley wiley.andrew.j at gmail.com
Fri Dec 16 23:56:01 PST 2011


On Sat, Dec 17, 2011 at 1:47 AM, Andrew Wiley <wiley.andrew.j at gmail.com> wrote:
> I was looking through Jonathan Davis's pull request to remove static
> constructors from std.datetime, and I realized that I don't know
> whether Double Checked Locking is legal under D's memory model, and
> what the requirements for it to work would be.
> (if you're not familiar with the term, check out
> http://en.wikipedia.org/wiki/Double-checked_locking - it's a useful
> but problematic programming pattern that can cause subtle concurrency
> bugs)
> It seems like it should be legal as long as the variable tested and
> initialized is flagged as shared so that the compiler enforces proper
> fences, but is this actually true?

This entry in the FAQ makes me suspicious:
```
What does shared have to do with memory barriers?

Reading/writing shared data emits memory barriers to ensure sequential
consistency (not implemented).
```

So DCL should be alright with data flagged as shared, but it's not
implemented in the compiler?


More information about the Digitalmars-d mailing list