This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: PATCH for thread-safe C++ static local initialization
- From: Jason Merrill <jason at redhat dot com>
- To: Wolfgang Bangerth <bangerth at ices dot utexas dot edu>
- Cc: gcc-patches at gcc dot gnu dot org, Benjamin Kosnik <bkoz at redhat dot com>
- Date: Fri, 20 Aug 2004 20:02:21 -0400
- Subject: Re: RFC: PATCH for thread-safe C++ static local initialization
- References: <200408201818.42186.bangerth@ices.utexas.edu>
On Fri, 20 Aug 2004 18:18:42 -0500, Wolfgang Bangerth <bangerth@ices.utexas.edu> wrote:
>> static <type> guard;
>> if (!guard.first_byte) {
>> if (__cxa_guard_acquire (&guard)) {
>> bool flag = false;
>> try {
>> // Do initialization.
>> flag = true; __cxa_guard_release (&guard);
>> // Register variable for destruction at end of program.
>> } catch {
>> if (!flag) __cxa_guard_abort (&guard);
>> }
>> }
>> }
>
> I assume that this is just my misunderstanding of the inner workings of how
> the guard works, but isn't there
>
> a) a second if(!guard.first_byte) missing inside the guarded block? (Some
> other thread may have set it between out checking for the flag and getting to
> the __cxa_guard_acquire.)
This happens in __cxa_guard_acquire.
> b) code missing to set guard.first_byte to something nonzero?
This happens in __cxa_guard_release.
> In any case, the main point of this mail is to point you (and this archived
> thread) to
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13684
> which you are doubtlessly aware of and which discusses this stuff.
I wasn't, thanks.
Jason