Subj : Re: posix and lock-free algorithms To : comp.programming.threads From : David Schwartz Date : Thu Aug 11 2005 05:53 am "John Doug Reynolds" wrote in message news:1123758229.821292.319380@o13g2000cwo.googlegroups.com... >> Singleton* Singleton::instance () { >> Mutex m; >> if (pInstance == 0) { >> Lock lock; >> if (pInstance == 0) { >> Singleton* tmp = new Singleton; >> m.lock(); m.unlock(); // just a memory barrier >> pInstance = tmp; > But the "reader" thread does place a memory barrier between its read > of pInstance and any attempt to access *pInstance. Since you must lock and unlock a mutex every time you pass through this code, it's really not DCL. It's just normal locking with extra overhead. Hypothetically, there could be reduced contention. DS .