Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-13 17:06:32


> > >> mutex m;
> > >> condition cv;
> > >> volatile bool a = false, b = false, c = false;
> > ^^^^^^^^
> > you do not need volatiles here.
> >
>
> Even on a multi-processor system?

yes.

> Does the language guarantee that this will work?

*POSIX* does.

> If so, then what is the point of volatile?

AFAIK the only *portable* usage of "volatile"
is for static volatile sig_atomic_t variables.
but that has nothing to do with multiple threads
and is supposed to work in single threaded program
and its signal handler(s) only (or in multithreaded
program but which reads/writes static volatile
sig_atomic_t variables on the same thread; your
"sig_atomic_t" signal handler should be enabled
on only one thread which is used to "process"
corresponding sig_atomic_t variable(s)).

to be portable you have to serialize *all* your
writes/updates which should also preclude *any*
concurrent reads (unless you have read access only).
you should do it using portable synch. functions
such as mutex.lock, join, semaphore.wait, rwlocks,
etc.. *not* using any volatiles - it simply does
not help at all and could just hurt performance,
instead.

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk