Re: [patch] spinlocks: remove 'volatile'

Linus Torvalds
2006-07-07T22:06:31Z

On Fri, 7 Jul 2006, Linus Torvalds wrote:
>
> It still makes a difference for code generation, OF COURSE. But it's the
> wrong thing to use.

And if you don't realize that my argument wasn't "bait-and-switch", it's
exactly the same thing. You pointed out a place where "volatile" would
make the code "work".

AND I POINTED OUT THAT EVEN IN YOUR TRIVIAL EXAMPLE, VOLATILE WAS
ACTUALLY THE WRONG THING TO DO.

And that's _exactly_ because the language environment (in this case the
CPU itself) has evolved past the point it was 30 years ago.

And my point is that this is _always_ true. There are basically no valid
uses where you can use "volatile" today, where there isn't some reason why
you _should_ have done it another way entirely. Either you should have
used proper locking, or you should have used the proper IO accessor
functions, or you should have used something like "cpu_relax()", OR ANY
NUMBER OF OTHER MECHANISMS.

(I did give a few examples of where "volatile" can be valid, but they are
very limited)

Yes, "volatile" is convenient - at the cost of making the compiler
generate crap code even when it shouldn't need to. Yes, "volatile"
sometimes allows you to be lazy and not do the proper thing. Yes,
"volatile" can hide bugs when you _tried_ to do the proper thing but
screwed up.

But can't you see that _none_ of those 'Yes, "volatile" ...' actually
means that you should _use_ "volatile".

Linus