This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13487] Construction of local static objects is not thread-safe
- From: "gianni at mariani dot ws" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Jul 2004 21:09:23 -0000
- Subject: [Bug c++/13487] Construction of local static objects is not thread-safe
- References: <20031225023132.13487.rmerkert@alphatech.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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