[linux-audio-dev] Re: Shared memory

Alfons Adriaensen fons.adriaensen at alcatel.be
Fri Jul 25 11:01:01 UTC 2003


On Fri, Jul 25, 2003 at 04:58:35PM +0300, Juhana Sadeharju wrote:

> So, there is no "do not optimize away apperent volatile variables"?
> Volatile variables in shmclient are easily recognized -- at least
> I recognized them. It is the array variable which content is only
> read but never written.
> 
> No such optimization flag? Can't believe that compilers are that dump.

You gave the answer yourself: what is an 'apparent volatile' variable ?
Almost any algorithm you may think of will be wrong 50% of the time.
Your code is not a good example to show it should be possible to 
detect 'apparently volatile' data -- it's too simple. If you would
have written to num [1] somewhere, would that make it less volatile ?

You have a complete application in your mind, and things may seem clear,
but the only thing your compiler sees is the single file it is compiling.

99.99% of all code written does not involve volatile data, most coders
are not even aware that it exists, so it is reasonable for a language
or compiler to assume that data is not volatile unless this is explicitly
stated. This has been so even before the 'volatile' keyword was introduced
in C. Before that time the only safe way to access volatile data was by
using an external function to do it. 

It's not a big deal, if you know your data can be modified in ways not
visible in the source code, use 'volatile'. It becomes a habit.

-- 
FA






More information about the Linux-audio-dev mailing list