Re: volatile is ignored by my compiler?
Hei wrote:
And I let the program continue for few minutes. It still prints "it
is not ready".
Any idea?
Does the compiler's documentation tell you that this will work? The
language definition does not require volatile to impose synchronization
on a variable that's accessed from multiple threads. If one thread is
running on one CPU and the other thread on another CPU, writing from one
thread writes to that CPU's cache; the other CPU has its own cache, and
won't see that change until the write is flushed to main memory and the
previously read value is replaced from main memory. To make that happen,
you need synchronization; typically through a mutex or a condition variable.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]