Re: standard atomic read bool exist?
On Feb 20, 12:31 am, Phil Endecott
Does there exist a standard way to atomically read the value of a
Not a standard way, no.
const bool SafelyReadValue() const
// What goes here to prevent the need for locks
// If multiple threads may reach this point?
I'm not aware of any common hardware platforms where you can't
simply read the bool normally, as it's small enough that the
read is atomic on the bus.
I think you're playing on words. When people ask about atomic
access, they generally mean that one thread can write, and
another can read, without problems. Possible splitting (half of
the value being written, then the other thread reading the
entire value, then the other half being written) is almost
certainly not a problem here, but all of the other usual
synchronization concerns are.
There are plenty of other things to worry about though, e.g.
the compiler or the hardware re-ordering the access to the
bool amongst the other operations, the compiler optimising it
Exactly. Some form of external synchronization is necessary, or
undefined behavior occurs. (According to Posix, I think
Windows, and the upcoming C++0x.)
James Kanze (GABI Software) email:email@example.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