This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]