Double Checked Locking

Martin Nowak dawg at dawgfoto.de
Wed Jan 4 16:09:26 PST 2012


On Sat, 17 Dec 2011 08:47:43 +0100, 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?

I've written down some idioms I use for this.
https://gist.github.com/1562943

If we could generalize and probably verify them,
they'd make a great addition to the standard library.

martin


More information about the Digitalmars-d mailing list