Darren New wrote: > Christopher Smith wrote: >> Pointer assignment *isn't* guaranteed to be atomic by >> the language and even if it is the code presented should produce the >> exact same code for assignment with any decent compiler. > > I think the point was that the check for nullness and the following of > the indirection isn't atomic. Not that two people might assign at the > same time, but that you might get > > if (p != null) > <zap> set p null </zap> > return *p;
Interestingly, due to the magic of optimization, this turns out to be much less of a problem than you'd think. In general though, even *reads* of pointers aren't guaranteed to be atomic by the language, so the only way to be certain is to lock around everything you are doing, using the sample code or not. --Chris -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
