Path: csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!weretis.net!feeder4.news.weretis.net!news.albasani.net!feed.cnntp.org!news.cnntp.org!not-for-mail From: Anthony Williams Newsgroups: comp.programming.threads Subject: Re: forcing the compiler to reload from memory with c++0x References: <4d3cee42$0$1209$426a74cc@news.free.fr> <1d21ad0a-db55-460e-aeb6-66f6d19369ea@i13g2000yqe.googlegroups.com> <4d3e2e3f$0$21517$426a34cc@news.free.fr> <4D40A4C7.16E6F9AE@web.de> <69d82db7-34be-4de7-86c4-2f39cc1e6df3@m13g2000yqb.googlegroups.com> <4d4221e9$0$17247$426a74cc@news.free.fr> <6de164c4-4e91-4c94-a8c8-240349de9cd2@x18g2000yqe.googlegroups.com> <4d45e2d2$0$27524$426a74cc@news.free.fr> Date: Tue, 01 Feb 2011 23:33:39 +0000 Message-ID: <87fws7wcrw.fsf@justsoftwaresolutions.co.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:SWEhVcsvgWb7osrzxPRnfcqM/dM= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 46 Organization: CNNTP NNTP-Posting-Host: d87b2cac.read.cnntp.org X-Trace: DXC=4Z3W`n_RjUImDY58?I6N=KWoT\PAgXa?A1LKeO=ej5ZH31?8ZVJ3gMEGj6PdB418WN5T7l@;5VQ8A;H_g\f?ddjC X-Complaints-To: abuse@cnntp.org Xref: csiph.com comp.programming.threads:1805 Joshua Maurice writes: > On Jan 30, 2:14 pm, David Jobet wrote: >> If it applies, then it means that an atomic load relaxed implies : >> - no ordering guarantee (that one everybody agrees) > > Actually, I don't think that I agree. > > I admit I'm not the best on this, but it's my understanding that each > atomic variable has a modification order, and no reads can read values > in an order which is inconsistent with this modification order. Is > this right? Ex: > > //all loads and stores are std::memory_order_relaxed > //start up the two threads simultaneously > > //initial condition > x = 0; > > //thread 1 > x = 1; > x = 2; > x = 3; > x = 4; > > //thread 2 > cout << x << endl; > cout << x << endl; > cout << x << endl; > cout << x << endl; > > It's my understanding that the program may not print the following. Is > that correct? > 1 > 3 > 2 > 4 Yes, that is correct. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976