------- 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