This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH, libstdc++] Fix PR54172
- From: Benjamin De Kosnik <bkoz at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 6 Sep 2012 11:41:38 -0700
- Subject: Re: [PATCH, libstdc++] Fix PR54172
- References: <3027697.Y09XNY3VZT@tjmaciei-mobl2>
> The attached patch fixes a race condition in __cxa_guard_acquire, a
> regression from 4.6. When the code was refactored to use the new
> atomic intrinsics, the fact that __atomic_compare_exchange_n updates
> the "expected" variable with the current value was missed.
>
> That causes the loop to possibly overwrite a successful
> initialisation and re- start the initialisation phase. The bug report
> has a gdb trace with a watchpoint showing the guard variable
> transitioning
>
> 0 (uninit) -> 256 (pending) -> 1 (done) -> 256 (pending) -> 1
> (done)
>
> This situation can happen if both CAS fail in given thread: the first
> because the other thread started the initialisation and the second
> because the initialisation succeeded.
This is ok.
-benjamin