[cpp-threads] C++ committee meeting in Mont Tremblant
Peter Dimov
pdimov at mmltd.net
Sun Oct 23 21:17:13 BST 2005
Doug Lea wrote:
> Peter Dimov wrote:
>> Doug Lea wrote:
>>
>>> Ben Hutchings wrote:
>>
>>>> I agree that static initialisation can currently be much more
>>>> difficult than it really should be. However, this problem is not
>>>> really on-topic for this list, so can we leave the matter now?
>>>
>>>
>>> Well, there IS the back-door issue about memory-model rules that
>>> may apply to guarantee ordering and visibility of static
>>> initializers.
>>
>> Can you give an example of the issue?
>
> Not knowing anything about what is being proposed, I don't know
> if it applies, but if static initialization need not precede
> construction of multiple threads, you may need something to ensure
> that the statically-initialized value of globalStruct.aField is
> visible to any thread that can read globalStruct.
Static initialization, as used by the C++ standard:
int x; // zero
int y = 5;
happens before the main thread is started, and before dynamic
initialization. Static initialization can't spawn threads, only dynamic
initialization:
int z = f();
W w;
can.
If a thread that has been spawned by a dynamic initializer accesses another
object with static storage duration and a dynamic initializer without
intervening synchronization, this is a data race and visibility is
irrelevant.
More information about the cpp-threads
mailing list