This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads
- From: "jason at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Apr 2005 07:39:05 -0000
- Subject: [Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads
- References: <20040114172507.13684.evijaykumar@yahoo.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From jason at redhat dot com 2005-04-14 07:38 -------
Subject: Re: local static object variable constructed once
but ctors and dtors called multiple times on same memory when called in
multiple threads
DCL with explicit memory barriers is safe. That's what I'm using. But
don't take my word for it, see the "DCL is Broken" Declaration:
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
Scroll down to "Making it work with explicit memory barriers".
The fast path does not use a lock. There, the only overhead compared to
the old code is a function call and a read/read hoist memory barrier on
targets where the memory barrier is necessary; targets that do not reorder
loads have no overhead at all.
It is impossible for users to implement this protection as efficiently as
the compiler can.
The C++ committee is working on improving thread support in C++; when this
particular topic came up the other day, there was general support for
having the compiler guarantee that the initialization be threadsafe, though
possibly with a keyword to either enable or disable this guarantee.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13684