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


Groups > comp.programming.threads > #1822

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 (2 earlier) <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> <947b33d5-2509-4f0c-9256-a7c3de35578e@24g2000yqa.googlegroups.com>
Date 2011-01-28 08:01 +0000
Message-ID <87mxmlxxry.fsf@justsoftwaresolutions.co.uk> (permalink)
Organization CNNTP

Show all headers | View raw


frege <gottlobfrege@gmail.com> writes:

> Now once you start talking C++0x, I don't *think* anything changes
> (particularly since the standard tries to follow current practice, not
> make up something new), but I can't actually quote chapter and verse
> as to why.  In particular, even though we code in it every day, it is
> hard to say exactly what memory is, and thus what volatile does and
> doesn't do, what the atomic ops do, etc - in a precise, technical-
> standard kind of way.  For me at least.

In C++0x, if there are non-atomic accesses to an object from multiple
threads, and at least one of them is a write then you have a "data race"
and undefined behaviour. Volatile still has nothing to do with
threading.

If you don't think any ordering guarantees are required then use atomic
operations with memory_order_relaxed. However, be aware that writes with
relaxed operations can be reordered just like non-atomic writes, so you
might well need a fence just to prevent the compiler reordering.

If you are only using your fence to prevent compiler reordering then you
can use atomic_signal_fence rather than atomic_thread_fence. The former
is primarily a compiler directive, and will likely not issue any CPU
instructions.

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 | NextPrevious in thread | Find similar


Thread

Re: forcing the compiler to reload from memory with c++0x frege <gottlobfrege@gmail.com> - 2011-01-27 21:56 -0800
  Re: forcing the compiler to reload from memory with c++0x Dmitriy Vyukov <dvyukov@gmail.com> - 2011-01-28 00:54 -0800
  Re: forcing the compiler to reload from memory with c++0x Andy Venikov <swojchelowek@gmail.com> - 2011-01-28 15:28 -0500
    Re: forcing the compiler to reload from memory with c++0x frege <gottlobfrege@gmail.com> - 2011-01-28 19:58 -0800
  Re: forcing the compiler to reload from memory with c++0x Anthony Williams <anthony.ajw@gmail.com> - 2011-01-28 08:01 +0000

csiph-web