This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin 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]

gcc problem with static instance destructors


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


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