Re: volatile char



Er... Isn't it have any use in multithread programming?

Maybe it's my misunderstanding, but according to my understanding the
"volatile" keyword will turn off optimization to that particular variable,
so the code will always fetch the value from main memory, instead of using
the value located in register or whatever places. So sometimes I do use
"static volatile" variables as interprocess controls.

"David Lowndes" <davidl@xxxxxxxxxxxxxxx>
???????:snnhc1hgjcvh11gloocnaib891mbnhl4c9@xxxxxxxxxx
>> I saw a keyword 'volatile' in a embedded system code.
>>Does that will use in VC? and What is that mean?
>
> volatile means that the value of the variable can change without the
> compiler knowing about it. It's of little (no) use in normal Win32
> user mode programming since it's almost always only useful in
> memory-mapped I/O situations.
>
> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq


.



Relevant Pages

  • Re: volatile char
    ... Isn't it have any use in multithread programming? ... > "volatile" keyword will turn off optimization to that particular ... It may indeed turn off such an optimization, but it does not help any. ... distinguish between your thread reading a cached value from a register, ...
    (microsoft.public.vc.language)
  • Re: [PATCH] "volatile considered harmful" document
    ... "Volatile is often used to prevent optimization, ... +safe (spinlocks, mutexes, memory barriers, etc.) are designed to prevent ... +primitives act as memory barriers - they are explicitly written to do so - ...
    (Linux-Kernel)
  • Re: [PATCH] "volatile considered harmful" document
    ... Just tell the reasons why volatile is bad and what should be used instead, ... "Volatile is often used to prevent optimization, ... Access to data must be protected and handled with kernel provided synchronization, ... +primitives act as memory barriers - they are explicitly written to do so - ...
    (Linux-Kernel)
  • Re: i386 nmi_watchdog: Merge check_nmi_watchdog fixes from x86_64
    ... > after the store without volatile it seems a reasonable ... > as we have taken the address earlier so at some point the compiler ... pointer away and will be referring to it later. ... or if the compiler does whole-program optimization and can see ...
    (Linux-Kernel)
  • Re: Share .cpp and .h along projects
    ... correct compiler behavior for MT programming WRT these operations ... you use the volatile keyword for variables that are volatile. ... an opaque DLL suppresses this optimization, ... the compiler could look into the DLL, there would have to be some way to ...
    (microsoft.public.vc.language)