Originally Posted by
CornedBee
A release doesn't do anything without an acquire to synchronize with, and the thing about DCL is that the second thread never acquires the mutex, and thus never synchronizes with the release.
Doesn't this fix it?
Code:
if(global_ptr == 0){
mutex->Lock();
if(global_ptr == 0)
{
tmp = new Object();
writebarrier();
global_ptr = tmp;
}
mutex->Unlock();
}
In other words, it wasn't the second thread's fault, it was the initializing thread's fault for not ensuring the ordering.