qt-interest@trolltech.com
[Top] [All Lists]

Re: What does "volatile" mean in mutil-thread programming?

Subject: Re: What does "volatile" mean in mutil-thread programming?
From: Werner Van Belle
Date: Wed, 20 Feb 2008 07:03:45 +0100
Werner Van Belle wrote:
> Kermit Mei wrote:
>> Hello all!
>> In embedded C++ code, the keyword "volatile" can prevent the complier
>> from optimizing it.
>> But, in mutil-thread programming, what dose it mean?
>> Look the following code as an example, I wish you would like to explain
>> it for me.
> 
> It means that any thread accessing the variable should read it again and
> not rely on some form of caching. E.g. If you want to wait until the
> thread stopped you can write something like
> 
> while (thread->stopped) sleep(1);

Reading my own post, I meant:

while (!thread->stopped) sleep(1);

it does however make no difference in the explanation.

-- 
Dr. Werner Van Belle
http://werner.yellowcouch.org/

<Prev in Thread] Current Thread [Next in Thread>