Re: Synchronization and volatile
On Jan 2, 9:37 am, Pavel Shved <Pavel.Sh...@gmail.com> wrote:
[...]
Note the difference between `shared' and `thread-safe'.
That's not the same neither it's intenden to be. Reading
about these higher matters you've missed the basic volatile
purpose. You need `volatile' in the case described because
whole your thread-safe object could be cached into processor's
registers and every thread would have its own copy of the
_shared_ _thread-safe_ object.
That may be its purpose, but as it is implemented in most common
compilers, it doesn't guarantee that. Modern processors have a
lot of registers which the program can't access directly, e.g.
in the pipeline. Ensuring that a value is not in the pipeline
requires special machine instructions: the use of a lock prefix
in i86, a membar instruction in Sparc, etc. None of the
compilers I've tried (VC++, g++ and Sun CC) generate this extra
code for accesses to volatile, so basically, volatile is nothing
but a comment. Or a hook into the type system, which is what
Andrei's code depends on.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34