gcc problem with static instance destructors

Joe Buehler jbuehler@hekimian.com
Tue Jul 30 08:01:00 GMT 2002


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



More information about the Cygwin-developers mailing list