Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Compiler or...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 15 Topic 9538 of 9775
Post > Topic >>

Re: Compiler ordering barriers in C++0x

by Anthony Williams <anthony_w.geo@[EMAIL PROTECTED] > May 3, 2008 at 06:13 AM

Szabolcs Ferenczi <szabolcs.ferenczi@[EMAIL PROTECTED]
> writes:

> On May 2, 12:43 pm, Anthony Williams <anthony_w....@[EMAIL PROTECTED]
> 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). If you're using atomics, that means you
must
have (at least) a release on some atomic variable by the modifying thread
after the modify, and an acquire on the same atomic variable by the other
thread before its access (read or write).

If you have N threads accessing the shared data, and one does a modify,
all
the other N-1 threads must be properly synchronized with the modifying
thread
as above in order to avoid data races.

Of course, you could also just use a mutex lock or join with the thread
doing
the modification.

Anthony
-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 15 Posts in Topic:
Compiler ordering barriers in C++0x
Dmitriy Vyukov <dvyuko  2008-04-24 01:04:20 
Re: Compiler ordering barriers in C++0x
nickf3 <nickf3@[EMAIL   2008-04-28 01:59:21 
Re: Compiler ordering barriers in C++0x
Anthony Williams <anth  2008-05-02 04:43:58 
Re: Compiler ordering barriers in C++0x
Szabolcs Ferenczi <sza  2008-05-02 12:48:39 
Re: Compiler ordering barriers in C++0x
Anthony Williams <anth  2008-05-03 06:13:29 
Re: Compiler ordering barriers in C++0x
"Dmitriy V'jukov&quo  2008-05-03 06:13:29 
Re: Compiler ordering barriers in C++0x
Anthony Williams <anth  2008-05-03 16:12:38 
Re: Compiler ordering barriers in C++0x
"Chris Thomasson&quo  2008-05-04 17:15:28 
Re: Compiler ordering barriers in C++0x
"Chris Thomasson&quo  2008-05-04 17:15:07 
Re: Compiler ordering barriers in C++0x
Szabolcs Ferenczi <sza  2008-05-04 17:17:14 
Re: Compiler ordering barriers in C++0x
"Chris Thomasson&quo  2008-05-05 07:09:38 
Re: Compiler ordering barriers in C++0x
Anthony Williams <anth  2008-05-05 07:08:05 
Re: Compiler ordering barriers in C++0x
Dmitriy Vyukov <dvyuko  2008-05-05 07:08:12 
Re: Compiler ordering barriers in C++0x
James Kanze <james.kan  2008-05-05 08:32:47 
Re: Compiler ordering barriers in C++0x
Szabolcs Ferenczi <sza  2008-05-05 12:35:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:53:30 CDT 2008.