Re: [RFC/PATCH] doc: volatile considered evil

Satyam Sharma
2007-05-08T20:08:05Z

On 5/8/07, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> On Mon, 30 Apr 2007 23:56:42 -0700 Andrew Morton wrote:
>
> > Oh my eyes. What are these doing?
> >
> > The volatiles are a worry - volatile is said to be basically-always-wrong
> > in-kernel, although we've never managed to document why, and i386
> > cheerfully uses it in readb() and friends.
> >
> > Perhaps if you can describe presisely what's going on here, alternatives
> > might be suggested.
>
> [well, can be turned into a patch]
>
> Here are some 'volatile' comments from Linus, extracted from
> several emails in at least 2 threads.
>
> If this is close to useful, we can add it to Documentation/.

Yes, definitely. Say Documentation/volatile-usage.txt -- this raw
version could be touched a little bit, to have sections that clearly
explain (1) how volatile makes the compiler generate trashy code, (2)
why volatile doesn't even do what people _think_ it does, considering
code is executed out-of-order by _hardware_ these days and not due to
compilers like was the case 20 years back, (3) and so volatile ends up
_hiding_ bugs from people and thus should be consigned to the trash
can of history, (4) _except_ for _really special_ usage cases like
reading IO mapped as memory.