lkml.org 
[lkml]   [2006]   [Sep]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Uses for memory barriers
On Fri, 8 Sep 2006, Oliver Neukum wrote:

> Am Freitag, 8. September 2006 17:55 schrieb Alan Stern:
> > >     CPU 0                   CPU 1
> > >     -----                   -----
> > >     while (y==0) relax();   y = -1;
> > >     a = 1;                  b = 1;
> > >     mb();                   mb();
> > >     y = b;                  x = a;
> > >                             while (y < 0) relax();
> > >                             assert(x==1 || y==1);   //???
>
> y = -1
> a = 1
> y =b (== 0)
> b = 1
> x = a (==1)

So in this case the assertion is satisfied because x == 1. My question
was whether the assertion could ever fail. Paul said that it could, but I
didn't find his reason convincing.

> > Disagree: CPU 0 executes mb() between reading y and b.  You have assumed
> > that CPU 1 executed its write to b and its mb() before CPU 0 got started,
> > so why wouldn't CPU 0's mb() guarantee that it sees the new value of b?  
> > That's really the key point.
>
> That code has an ordinary race condition.
> For it to work it needs to be:
>
> b = 1;
> mb(); //could be wmb()
> y = -1;

I'm not sure what you mean. The code wasn't intended to "work" in any
sense; it was just to make a point. My question still stands: Is it
possible, in the code as I originally wrote it, for the assertion to fail?

Alan Stern

-
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-09-08 20:09    [W:0.029 / U:7.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site