[Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads
jason at redhat dot com
gcc-bugzilla@gcc.gnu.org
Sat Sep 4 18:06:00 GMT 2004
------- Additional Comments From jason at redhat dot com 2004-09-04 18:06 -------
Subject: Re: local static object variable constructed once
but ctors and dtors called multiple times on same memory when called in
multiple threads
On 31 Aug 2004 06:41:13 -0000, "adah at netstd dot com" <gcc-bugzilla@gcc.gnu.org> wrote:
> It looks to me that the solution applies the Double-Checked Locking Pattern,
> and could be unsafe on some multi-processor platforms, most notably Alpha and
> IA-64.
Hmm, indeed. As I understand it from some googling, particularly this thread:
http://www.google.com/groups?threadm=6kuldj$4sk%40bmtlh10.bnr.ca
the problem is that modern architectures such as the ones you mention can
reorder stores and loads so that another processor could see the guard
variable set, but the controlled variable not yet fully initialized. The
cheapest workaround is to add memory barriers in the initialization path if
the architecture reorders stores (SPARC also does this) and in the
already-initialized path if it reorders loads.
Unfortunately, pthreads (for instance) don't have a portable way of forcing
a memory barrier other than with a mutex.
I suppose the simplest fix is just to remove the check in the
compiler-generated code, but having all calls to functions with initialized
static locals go through the same mutex seems rather unfortunate. Hmm.
Jason
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13684
More information about the Gcc-bugs
mailing list