Re: [patch] spinlocks: remove 'volatile'

Avi Kivity
2006-07-08T08:36:41Z

linux-os (Dick Johnson) wrote:
>
> >> The 'C' compiler has no choice but to actually make that memory access
> >> and read the variable because the variable is in another module
> (a.k.a.
> >> file).
>

[code showing the compiler may cache the access]

> So read the code; you have "10: jne 10", jumping to itself
> forever, without even doing anything else to set the flags, much
> less reading a variable.
>

Short attention span, eh? He's proven you wrong and you go on and talk
about something else.

> >
> >> However, if I have the same code, but the variable is visible during
> >> compile time, i.e.,
> >>
> >> int spinner=0;
> >>
> >> funct(){
> >> while(spinner)
> >> ;
> >>
> >> ... the compiler may eliminate that code altogether because it
> >> 'knows' that spinner is FALSE, having initialized it to zero
> >> itself.
> >
>

[code showing that defining the variable in the same translation unit
makes no difference]

> Then, you have exactly the same thing here:
> 10: 75 fe jne 10 <funct+0x10>
>
> Same bad code.
>

You seem to have forgotten that you claimed different code would be
generated.

--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.