Double Checked Locking
Regan Heath
regan at netmail.co.nz
Mon Dec 19 03:38:08 PST 2011
On Sun, 18 Dec 2011 11:55:10 -0000, Michel Fortin
<michel.fortin at michelf.com> wrote:
> 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.
Something like..
http://linux.die.net/man/3/pthread_once
I wrote a windows version of that once (pun intended), and I *think* it
works .. after reading Andrei's link I'm not so sure..
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list