[c++-pthreads] Initialization of local static mutex

Roland Schwarz roland.schwarz at chello.at
Sun Oct 8 17:19:36 UTC 2006


Mark Mitchell wrote:

> A standard-conforming compiler, used with a standard-conforming POSIX 
> library, cannot suffer from a race condition in the code that you posted 
> because PTHREAD_MUTEX_INITIALIZER must be a constant-expression.
> 

Sorry for keep on bugging, but did you read my citation from the
standard:

6.7/4:
"The zero-initialization of all local objects with static
storage duration is performed before any other initialization
takes place. A local object of POD type with static storage
duration initialized with constant-expressions is initialized
before its block is first entered. ..."

Does this mean, the compiler is allowed to emit code to initialize
the mutex variable at runtime, after "any other initializations
have taken place" and before "block is entered"?

A compiler is still conforming in this case, while at the same
time susceptible to the race.

We do not have the zero initialization case here, which would
be fine, but the initialization by constant-expression.

What am I missing here?

Roland



More information about the c++-pthreads mailing list