From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25601 invoked by alias); 14 Apr 2005 07:39:21 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 25498 invoked by alias); 14 Apr 2005 07:39:05 -0000 Date: Thu, 14 Apr 2005 07:39:00 -0000 Message-ID: <20050414073905.25497.qmail@sourceware.org> From: "jason at redhat dot com" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20040114172507.13684.evijaykumar@yahoo.com> References: <20040114172507.13684.evijaykumar@yahoo.com> Reply-To: gcc-bugzilla@gcc.gnu.org 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 X-Bugzilla-Reason: CC X-SW-Source: 2005-04/txt/msg01877.txt.bz2 List-Id: ------- 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