This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC 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]

c++/7458: private static objects not constructed in thread-safe fashion


>Number:         7458
>Category:       c++
>Synopsis:       private static objects not constructed in thread-safe fashion
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 31 13:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Joe Buehler
>Release:        2.95, 3.0.2
>Organization:
>Environment:
Cygwin, but generated code looks the same
on AIX, HPUX as far as I can tell
>Description:
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);
}
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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