On Sun, Aug 28, 2011 at 8:32 AM, Milian Wolff <m...@milianw.de> wrote: > On Saturday 27 August 2011 23:44:02 Jeffrey Walton wrote: >> Hi All, >> >> I want to use double checked initialization for a program, but I'm >> catching some warnings from helgrind. A typical use is shown below. >> >> Its kind of tedious to run --gen-suppressions=yes for to develop >> suppressions. Plus, the suppression rules are only applicable to the >> current name mangling scheme. >> >> Is there a helgrind friendly way to write the initialization so that I >> don't get a warning? > > Reading http://en.wikipedia.org/wiki/Double-checked_locking I'd think that the > warnings are valid - no? Only MSVC apparently interpretes volatile in a way > that would make this a safe pattern in C++. > > Can you explain why you think it's safe to use anyways, i.e. why you want to > ignore the warnings? :)
(1) Never trust wikipedia. One of the funniest (I recall) was the message to comp.compression where OP asked Dr. Adler why his reference implementation/RFC 1950 differed from wikipedia. "Need peer review: May have found mistake in Adler-32!", http://groups.google.com/group/comp.compression/browse_thread/thread/5a37a9fcd32786fd/9859a0c61a3fb333. (2) In GCC, I'm compiling with -fthreadsafe-statics (in reality, I'm *not* using -fno-threadsafe-statics). (3) For Visual C++ targets, we're using Visual Studio 2005 and above. (4) Order of initialization: either `init` is constructed first, or `shared_ptr<MyObject>` is constructed first. Either way, `init` is false and `shared_ptr<MyObject>` is nullptr before the first test. (5) `volatile` on `init` ensures the generated code performs a read of the memory, and does not use a cached value. (6) I actually examine the assembled code to verify its doing what I want. Jeff ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users