Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #1805

Re: forcing the compiler to reload from memory with c++0x

From Anthony Williams <anthony.ajw@gmail.com>
Newsgroups comp.programming.threads
Subject Re: forcing the compiler to reload from memory with c++0x
References (4 earlier) <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> <ee1296a2-2a54-42c2-b37c-5c9cf270ea4a@d23g2000prj.googlegroups.com>
Date 2011-02-01 23:33 +0000
Message-ID <87fws7wcrw.fsf@justsoftwaresolutions.co.uk> (permalink)
Organization CNNTP

Show all headers | View raw


Joshua Maurice <joshuamaurice@gmail.com> writes:

> On Jan 30, 2:14 pm, David Jobet <david.jo...@free.fr> 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

Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: forcing the compiler to reload from memory with c++0x David Jobet <david.jobet@free.fr> - 2011-01-30 17:14 -0500
  Re: forcing the compiler to reload from memory with c++0x Anthony Williams <anthony.ajw@gmail.com> - 2011-02-01 23:33 +0000
  Re: forcing the compiler to reload from memory with c++0x Joshua Maurice <joshuamaurice@gmail.com> - 2011-02-01 15:12 -0800
  Re: forcing the compiler to reload from memory with c++0x Dmitriy Vyukov <dvyukov@gmail.com> - 2011-01-31 01:07 -0800

csiph-web