Subj : Re: posix and lock-free algorithms To : comp.programming.threads From : David Schwartz Date : Thu Aug 11 2005 02:48 pm "Alexander Terekhov" wrote in message news:42FB7410.5FD8C256@web.de... > To begin with, even if compiler won't optimize-out your per-thread > locks (which is perfectly legal), compiler and/or hardware can > transform your > > : Singleton* tmp = new Singleton; > : local.lock(); local.unlock(); // just a memory barrier > : pInstance = tmp; > > to (in effect): > > < pseudo-code; assume everything is throw()-nothing > > > local.lock(); > pInstance = Singleton::operator new(); > ::new(pInstance) Singleton(); > local.unlock(); No, it can't. The POSIX lock/unlock functions are defined as synchronizing memory. If this means anything at all, it means loads/stores can't be reordered across those functions. DS .