This is the mail archive of the gcc@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]

private static object construction bug?


I entered a bug report on this (7458) that was promptly closed by
a Cygwin developer, but I believe incorrectly so, so I am posting here.

I think gcc is generating code that is not thread-safe for
the attached C++ code.  This is regardless of whether gcc is
compiled for thread support, and apparently regardless of platform,
or even gcc version.

The static variable inside the function is constructed on function
entry, but the construction is not thread-safe -- two threads calling
this function at about the same time can cause double construction of
the object etc.

This was found originally in gcc 2.95 under Cygwin (not compiled with
thread support), but I believe is not specific to cygwin or whether
thread support is on, or the particular version of gcc.

- I built a version of gcc 3.1.1 under AIX 4.3.3 with
  --enable-threads=posix, and it appears to have the bug.

- I checked the compiler on a RedHat 7.1 i386 box running 2.96,
  which looks to have been compiled with --enable-threads=posix,
  and it definitely has the bug.

I would appreciate it if someone familiar with the internals of
gcc could verify whether this is a real problem.

Joe Buehler

struct the_struct {
	int i;
	the_struct() {
		i = 0;
	};
	~the_struct() {
		i = 1;
	};
};

void
function()
{
	static the_struct temporary;
}


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