Re: [patch] spinlocks: remove 'volatile'

From: Arjan van de Ven
Date: Thu Jul 06 2006 - 09:42:00 EST



> > 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".


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/