This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
private static instance construction not thread-safe?
- From: Joe Buehler <jbuehler at hekimian dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 31 Jul 2002 10:48:15 -0400
- Subject: private static instance construction not thread-safe?
- Organization: Spirent Communications
- Reply-to: joseph dot buehler at spirentcom dot com
The attached C++ generates code that is not thread-safe,
when using the gcc 2.95 prebuilt for Cygwin and installable
via the Cygwin installer.
gcc inserts code at the top of f() to take care of construction
of the "temp" instance, and to schedule its destruction at program
exit time, using atexit().
The code that does this is not thread-safe -- two calls to f()
around the same time can cause double-construction, double
calls to atexit(), etc.
Is this a gcc bug, or a result of the way that the gcc I am using
has been configured? Or is some gcc option supposed to be used
that will take care of this?
My apologies if this has been asked a million times -- I did not
find anything in GNATS for gcc.
Joe Buehler
struct x {
int i;
x() {
i = 0;
}
~x() {
i = -1;
}
};
int
f()
{
static x temp;
return(temp.i);
}