private static object construction bug?
Mark Mitchell
mark@codesourcery.com
Mon Aug 5 15:00:00 GMT 2002
--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
More information about the Gcc
mailing list