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! ]