Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2005-09-13 11:37:25

Jason Hise <chaos_at_[hidden]> writes:

> 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?
> 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.

You can use call_once to initialize the mutex, or you can use a mutex type
that supports static initialization (unlike the current boost ones, but like a


Anthony Williams
Software Developer
Just Software Solutions Ltd

Boost list run by bdawes at, gregod at, cpdaniel at, john at