Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 03 May 2011 07:39:39 -0500 From: Pete Becker Organization: Roundhouse Consulting, Ltd. Newsgroups: comp.lang.c++ Date: Tue, 3 May 2011 08:39:39 -0400 Message-ID: <2011050308393971813-pete@versatilecodingcom> References: <78f3178b-efdc-4af5-8f84-7ff6fa995af7@e25g2000prf.googlegroups.com> <2011042613500411162-pete@versatilecodingcom> <428ddf1c-7074-4117-ae13-6d427cbe2ec4@34g2000pru.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: Please disprove this Double-Checked Locking "fix" User-Agent: Unison/2.1.4 Lines: 33 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-yCwK2zGhk1YvP5MNNxZzzXcsyf3+3fQ302WtR+S/KbPiQaN+u81CvMAYcn0X3h8v0JOj8oomfKMPsQ9!LQ8grAiXb1QN+M3D+55aXSdW+6OExVdzvSgXZBCw2b4crIMYKM1MwB9ilPqHZgbEOrP84pFd X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2587 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:4614 On 2011-05-02 18:59:49 -0400, Joshua Maurice said: > > What does change is when we throw std::atomic into the mix. When > pinstance is of type std::atomic, the following: > pinstance = new Singleton; > is equivalent to the following ala operator overloading pseudo-code > (forgive me for not knowing the specific function name offhand): > pinstance.set(new Singleton); Let me say that more strongly. std::atomic is a template instantiation. It has an assignment operator that takes an argument of type Singleton*. So in this code: std::atomic pinstance; pinstance = new Singleton; the assignment is implemented as a function call. All of the side effects of evaluating the argument to the function call happen before the call to the function, so the memory barrier that the assignment establishes ensures that all of the side effects will be visible to other threads before the assignment is visible. That guarantee, though, depends on both the definition of the atomic template and the new guarantees that compilers can't reorder instructions across atomic operations. -- Pete Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard C++ Library Extensions: a Tutorial and Reference (www.petebecker.com/tr1book)