lkml.org 
[lkml]   [2006]   [Jul]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [patch] spinlocks: remove 'volatile'
From
Date

> > 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-07-06 15:45    [W:0.102 / U:0.460 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site