Re: Compiler ordering barriers in C++0x
On May 5, 3:09 pm, "Chris Thomasson" <cris...@comcast.net> wrote:
"Szabolcs Ferenczi" <szabolcs.feren...@gmail.com> wrote in message
news:e97bdaf4-5f8a-40bd-b058-46b30b1eb01a@x35g2000hsb.googlegroups.com...
On May 3, 2:13 pm, Anthony Williams <anthony_w....@yahoo.com> wrote:
Szabolcs Ferenczi <szabolcs.feren...@gmail.com> writes:
On May 2, 12:43 pm, Anthony Williams <anthony_w....@yahoo.com> wrote:
[...]
All accesses to shared data MUST be synchronized with atomics: [...]
Can you elaborate this point please. How can you
generally synchronise N processes with help of atomics?
Do you mean only two processes under certain
circumstances?
If any thread modifies shared data that is not of type
atomic_xxx, the developer must ensure appropriate
synchronization with any other thread that accesses that
shared data in order to avoid a data race (and the
undefined behaviour that comes with that).
It is clear that you must synchronise access to shared
variable. Normally you must use a Critical Region for that.
It would be interesting to know what you mean by a "Critical
Region". My understanding of it is simply that it is a section
of code which is protected by some synchronization mechanism, so
that 1) only one thread can enter it at a time, and 2) memory
synchronization occurs on entering and leaving. In which case,
it's neither necessary nor sufficient to ensure "appropriate
synchronization". But I think Microsoft has redefined it to
mean something else.
I was curious how do you synchronise access to shared data
with atomics.
Really? How do you think some mutexs, semaphores, non-blocking
algorithms ect, ect, are actually implemented?
They synchronize access. On my usual platform (Sun Sparc), this
means inserting the appropriate membar instructions before
and/or after the access. Something which, of course, you can't
do in current C++; you need some inline assembler. (But you
know that.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]