"Thomas Richter" <thor@[EMAIL PROTECTED]
> wrote in message
news:gc7bcg$mnq$1@[EMAIL PROTECTED]
> Brian Cole wrote:
>> I know that static initialization is not considered threadsafe from
>> previous posts on this list. However, if a function static is POD
>> being initialized by a function call then the value should always be
>> initialized correctly, even if a inconsequential race condition
>> occurs. This assumes that POD assignments are atomic, what platforms
>> is this not true on?
>
> All I know of. For example,
>
> struct foo {
> int a,b;
> };
>
> static struct foo f = {1,2};
>
> is a POD initialization, and if two threads run into this line of code,
it
> may happen that thread A initializes f.b while thread B is already using
> f.b for something else, so no, this is definitely not safe. Even if you
> return a copy of f from a function:
>
> struct foo init_me(void)
> {
> static struct foo f = {1,2};
>
> return f;
> }
>
> the compiler may simply test a (non-mutex) protected flag in the
function
> and initialize f on the first call. If a second thread runs into the
> function, it is unclear whether f will be initialized a second time, or
> might return with a only partially initialized f instead. Similarly,
[...]
do you think that:
PTHREAD_MUTEX_INITIALIZER
is busted?


|