This is the mail archive of the
cygwin-developers@cygwin.com
mailing list for the Cygwin project.
gcc problem with static instance destructors
- From: Joe Buehler <jbuehler at hekimian dot com>
- Cc: Cygwin Developers <cygwin-developers at cygwin dot com>
- Date: Tue, 30 Jul 2002 11:01:08 -0400
- Subject: gcc problem with static instance destructors
- Organization: Spirent Communications
- References: <3D46828F.6090802@hekimian.com>
- Reply-to: joseph dot buehler at spirentcom dot com
Looking at the code generated by gcc, it looks like it generates
code that is not thread-safe in a certain case.
It appears that static instances inside functions cause gcc
to generate a call to atexit() to call the destructor at
program exit time.
Compile the following and look at the assembly generated by
gcc:
struct x {
int i;
x() {
i = 0;
}
~x() {
i = -1;
}
};
int
main()
{
static x temp;
return(temp.i);
}
- The code that is generated to call atexit() does not look thread-safe.
(handling of the flag variable that is tested to prevent duplicate calls)
- In addition, atexit() itself is not thread-safe.
So it looks like functions in cygwin that have internal static class instances
could be a serious source of problems.
This is using gcc-2.95.3-5.
Joe Buehler