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: Zack Weinberg <zack at codesourcery dot com>
- Cc: Joe Buck <Joe dot Buck at synopsys dot com>, "joseph dot buehler at spirentcom dot com" <joseph dot buehler at spirentcom dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Mon, 05 Aug 2002 16:05:11 -0700
- Subject: Re: private static object construction bug?
--On Monday, August 05, 2002 03:50:12 PM -0700 Zack Weinberg
<zack@codesourcery.com> wrote:
On Mon, Aug 05, 2002 at 01:58:18PM -0700, Mark Mitchell wrote:
if (!guard) {
__cxa_guard_acquire (&guard); // I forget the exact name.
// Construct variable.
__cxa_guard_release (&guard):
}
This sequence has two different races.
Yes; I was overly simplistic. You are of course correct.
It is likely that the ABI standard does specify something like this,
but I wanted to make sure people understood that thread-safe object
construction is not as simple as you made it look. (The guard
variable can't be a simple integer, either; it needs to be a structure
containing an integer and a mutex.)
Yes. The ABI says that guard is 64 bits long, and that one of the
bytes is a boolean. (Our current implementation just twiddles that
byte.) The idea is that __cxa_guard_acquire twiddles the byte in
a thread-safe way.
Thanks for clarifying.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com