Subj : Re: posix and lock-free algorithms To : comp.programming.threads From : Joe Seigh Date : Thu Aug 11 2005 06:41 pm David Schwartz wrote: > "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. > "synchronizing memory" is left undefined. I don't think you can supply your own arbitrary definition. Unless of course if you are a Posix implementer and then spontaneous comprehension of the true meaning of Posix will happen which by official Posix definition will be whatever thoughts are floating around your head at the time. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .