
13 Sep
2005
13 Sep
'05
4:12 p.m.
Anthony Williams wrote:
Calls through call_once are only atomic with respect to other calls that reference the same once_flag. If you want mutual exclusion, you need a shared mutex --- why not just create a function-local static mutex, lock it before your function call, and unlock it afterwards?
Anthony
Because static variables are not initialized in a thread safe manner (except on some versions of gcc which lock the operation). Multiple threads could end up calling the mutex's constructor simultaneously, resulting in a corrupted mutex object. If I have a global mutex, I need to find a way to initialize it before the program starts spawning threads. -Jason