This is the mail archive of the gcc-patches@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: RFC: PATCH for thread-safe C++ static local initialization


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


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