Re: Need to use "volatile" for accessing variables between threads?
On Jul 28, 7:41 am, "Chris M. Thomasson" <n...@spam.invalid> wrote:
"James Kanze" <james.ka...@gmail.com> wrote in message
news:524fc5b3-e99e-48af-bd56-a56ca74e7366@v36g2000yqv.googlegroups.com...
On Jul 27, 2:58 pm, Virchanza <virt...@lavabit.com> wrote:
Volatile is intended to be used where a variable's value
can mysteriously change outside of the normal flow of
code. I'm still not sure whether "a separate thread"
qualifies as being mysterious enough.
It's mysterious enough, in that sense. The point is that
your synchronization requests have already specified that
such changes can occur, outside the protected region. (In
fact, many compilers, such as Sun CC, g++ and VC++, don't
implement sufficient synchronization for volatile to be
usable for much of anything. Such compilers are arguably
broken, but you'll almost certainly have to use them.)
[...]
FWIW, MSVC compilers, versions 8 and above, automatically
insert load-acquire/store-release barriers for volatile loads
and stores on certain architectures (e.g., PowerPC):
I knew that Microsoft intended to do this; I hadn't seen it on
the compilers I'd verified. (I forget which version it was, but
it was on a 32 bit Intel.) Microsoft actually proposed this
extension to the meaning of volatile to the standardization
committee, and indicated that they were implementing it in their
compilers. (If I'm not mistaken, it corresponds to the meaning
of volatile in C#.)
--
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