[Bug c++/13487] Construction of local static objects is not thread-safe

gianni at mariani dot ws gcc-bugzilla@gcc.gnu.org
Sat Jul 3 21:09:00 GMT 2004


------- Additional Comments From gianni at mariani dot ws  2004-07-03 21:09 -------

> because the initializers are done when the module is loaded ...

That's not true.

"static" function variables are constructed the first time through the section
of code.

i.e.

int f( int a )
{
   static int x( a );
   return x;
}

...
    cout << z( 1 ) << " " << z( 2 );
...
prints "1 1".

also

int z( int a )
{
   if ( a & 1 )
   {
       static int v( a )
       return v;
   } else {
       static int v( a );
       return v;
   }
}

cout << z( 1 ) << " " << z( 2 ) " ";
cout << z( 3 ) << " " << z( 4 );

prints "1 2 1 2"




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13487



More information about the Gcc-bugs mailing list