Re: [patch] spinlocks: remove 'volatile'

Arjan van de Ven
2006-07-06T13:43:22Z

> > I did not talk about memory barriers. In fact, barrier() is NOT a memory
> > barrier. It's a compiler optimization barrier!
> >
>
> // Read 10 samples from 2 A/D converters.
>
> int* ina;
> int a[10];
> int* inb;
> int b[10];
>
> for (int i=0; i<10; i++)
> {
> a[i] = *ina;
> barrier();
> b[i] = *inb;
> }
>
> The barrier prevents the compiler of translating this to:
>
> for (int i=0; i<10; i++)
> {
> b[i] = *inb;
> a[i] = *ina;
> }
>
> or even to:
>
> for (int i=0; i<10; i++)
> a[i] = *ina;
> for (int i=0; i<10; i++)
> b[i] = *inb;
>
> but does not prevent it to do this:

yes it does. It's a full optimization barrier; the compiler assumes all
register and memory content has changed from before the barrier(), and
it will start "fresh".