[c++-pthreads] Initialization of local static mutex
Roland Schwarz
roland.schwarz at chello.at
Sun Oct 8 15:04:01 UTC 2006
Your answer does not yet silence my doubts:
George Shimanovich wrote:
> There will be no race condition between two static initializations and
> any static and non-static initialization:
> 1) The zero-initialization of static mutex is performed before its
> initialization with constant-expression PTHREAD_MUTEX_INITIALIZER
Ok, this is said by the first sentence of 6.7/4.
> 2) The initialization with that constant-expression occurs before any
> non-static initialization in foo
Ok, this is covered by the next sentence
> 3) Compiler makes sure that each static initialization is done only once
The 3) still puzzles me. If the compiler makes this sure, he has to
remember this fact somewhere, i.e. in a (global, hidden) state variable.
Access to this variable poses a race condition, and since the
PTHREAD_MUTEX_INITIALIZER might not be copied in an atomic manner, the
assignment itself is not thread safe.
Roland
More information about the c++-pthreads
mailing list