[cpp-threads] static locals

Peter Dimov pdimov at mmltd.net
Mon May 30 10:38:21 BST 2005


Hans Boehm wrote:
> On Sun, 29 May 2005, Peter Dimov wrote:
>
>> My opinion is that all local statics should be synchronized (as in
>> the IA64 ABI) and that __async volatile should not be introduced.
>> So... if I take a step back I see no need for new syntactic
>> additions. ;-)
>>
> If local statics are all synchronized, what does that mean about
> memory ordering between the initialization and prior assignments?
> If a local static pointer p is initialized to point to a newly
> allocated object Q, presumably the initialization of Q should be
> visible to
> other threads using p?  What does that mean for something like
>
> static int i(17);
>
> which would normally be handled at compile time?  Are other later
> users of i required to see stores performed by the first thread to
> reach the initialization?

The visibility semantics of a local static are as if the initialization has 
been performed by the current thread. So in the first example

void f()
{
    static Q* p = new Q( ... );
}

the writes done by the constructor of Q should be visible to all threads 
that call f.

In your second example, the initialization is done at compile/link/load 
time, as usual. 





More information about the cpp-threads mailing list