On Saturday, December 17, 2011 22:16:38 Michel Fortin wrote: > On 2011-12-17 23:10:19 +0000, Andrei Alexandrescu > > <seewebsiteforem...@erdani.org> said: > > On 12/17/11 5:03 PM, Jonathan M Davis wrote: > >> Well, you learn something new every day I guess. I'd never even heard > >> of > >> double-checked locking before this. I came up with it on my own in an > >> attempt to reduce how much the mutex was used. Is the problem with it > >> that the write isn't actually atomic? Wikipedia makes it sound like > >> the problem might be that the object might be partially initialized > >> but not fully initialized, which I wouldn't have thought possible, > >> since I would have thought that the object would be fully initialized > >> and _then_ the reference would be assigned to it. And it's my > >> understanding that a pointer assignment like that would be atomic. Or > >> is there more going on than that, making it so that the assignment > >> itself really isn't atomic? > > > > There so much going on about double-checked locking, it's not even > > funny. Atomic assignments have the least to do with it. Check this out: > > http://goo.gl/f0VQG > > 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. - Jonathan M Davis