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]

Re: 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've squashed the example a bit, but here it is:

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

void function() {
	static the_struct temporary;
}

The decision to close the bug report was correct.

> I think gcc is generating code that is not thread-safe for
> the attached C++ code.

Sorry, but the version of "thread-safe" that you are asking for would
require substantially slower code: you appear to want thread-safe locking
for the creation of all objects (in your case, for the construction of
a static variable that is local to a function).  GCC is never going to do
that.  The speed penalty would be enormous.

When we talk about thread-safety, what is meant is that any allocation
mechanism that exists "behind the scenes", like reference-counted string
objects or allocation pools, can't introduce any thread conflict issues.
However, no locking code is introduced for objects that can be potentially
accessed in different threads, such locking is up to the application
programmers.

To understand the kind of thread safety the compiler and the library
provide, see

http://www.sgi.com/tech/stl/thread_safety.html

(this is an SGI document, but the philosophy used by GCC is essentially
the same).

Here is the example:




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