This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: private static object construction bug?
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Joe Buck <Joe dot Buck at synopsys dot com>, "joseph dot buehler at spirentcom dot com" <joseph dot buehler at spirentcom dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Mon, 05 Aug 2002 13:58:18 -0700
- Subject: Re: private static object construction bug?
--On Monday, August 05, 2002 09:48:49 AM -0700 Joe Buck
<Joe.Buck@synopsys.com> wrote:
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.
Actually, I think it was only sort-of correct.
The ABI specifies functions a compiler can use to get thread safe
construction of local temporaries. The compiler can choose not to
use them. G++ makes that choice, but partly due to not getting
around to calling the functions. The intended code sequence is
not really any slower after the object has been constructed.
Right now, we do this approximately (there are exceptions to worry
about!):
if (!guard) {
guard = 1;
// Construct variable.
}
The new sequence would be:
if (!guard) {
__cxa_guard_acquire (&guard); // I forget the exact name.
// Construct variable.
__cxa_guard_release (&guard):
}
So, you pay two extra function calls the first time into the function,
and nothing thereafter, modulo space.
So, the compiler is ABI compliant, but as QOI issue we should probably
use the functions.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com