On 2011-12-17 23:10:19 +0000, Andrei Alexandrescu <[email protected]> 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.

--
Michel Fortin
[email protected]
http://michelf.com/

Reply via email to