Double Checked Locking

Michel Fortin michel.fortin at michelf.com
Sun Dec 18 03:55:10 PST 2011


On 2011-12-18 04:35:08 +0000, Jonathan M Davis <jmdavisProg at gmx.com> said:

> On Saturday, December 17, 2011 22:16:38 Michel Fortin wrote:
>> Shouldn't a properly implemented double-checked locking pattern be part
>> of the standard library? This way people will have a better chance of
>> not screwing up. I think the pattern is common enough to warrant it.
> 
> Well, from the sounds of it, the basic double-checked locking pattern would
> work just fine with a shared variable if shared were fully implemented, but
> since it's not, it doesn't work right now. So, I don't know that we need to do
> anything other than finish implementing shared.

I meant something higher level so you don't even have to think about 
double-checked locking. Something like this:

	AssignOnce!(shared MyClass) c;
	c = { new shared MyClass }; // the delegate literal is called only the 
first time
	c.blahblah(); // c is guarantied to be initialized at this point

...or something similar.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list