digitalmars.D - Double Checked Locking
- Andrew Wiley (11/11) Dec 16 2011 I was looking through Jonathan Davis's pull request to remove static
- deadalnix (5/16) Dec 27 2011 Well according to the spec, it should work with the garantee given by
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?
Dec 16 2011
Le 17/12/2011 08:47, Andrew Wiley a écrit :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?Well according to the spec, it should work with the garantee given by shared. But in real life, the compiler is unable to ensure that. This is compiler issue.
Dec 27 2011