Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #1777
| From | Anthony Williams <anthony.ajw@gmail.com> |
|---|---|
| Newsgroups | comp.programming.threads |
| Subject | Re: forcing the compiler to reload from memory with c++0x |
| References | (3 earlier) <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 | 2011-01-31 09:11 +0000 |
| Message-ID | <878vy1xwse.fsf@justsoftwaresolutions.co.uk> (permalink) |
| Organization | CNNTP |
David Jobet <david.jobet@free.fr> writes: > 1.10/25 seems to be talking about a store right ? Yes. > So, if I'm doing atomic_int.load(std::memory_order_relaxed) > > does 1.10/25 still apply ? Your load must see one of the values written that is consistent with any other memory ordering constraints that apply. > If it applies, then it means that an atomic load relaxed implies : > - no ordering guarantee (that one everybody agrees) > - the load cannot be cached/optimized out, because regardless of the > ordering model used, we're talking about an atomic here, and operation > on atomics (even load) must become visible in a finite time (I wasn't > aware of that one) Repeated loads of the same variable can be optimized out unless intervening operations impose ordering constraints. However, it is the "early" loads that can be optimized out, not the "later" ones: the compiler cannot read the value once and then cache it forever, as this means that stores done by other threads won't become visible to that thread, and 1.10/25 is violated. The compiler can skip any finite number of loads, but must sooner or later execute a real load. > Corrolary : if I'm doing my own impl of atomic load relaxed in c++98, > does it mean that even a load relaxed implies a memory clobber so that > the compiler cannot optimize the value out ? With gcc, then yes. 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 | Find similar
Re: forcing the compiler to reload from memory with c++0x Anthony Williams <anthony.ajw@gmail.com> - 2011-01-31 09:11 +0000
csiph-web