lkml.org 
[lkml]   [2015]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kernel: fix data race in put_pid
On 09/18, Dmitry Vyukov wrote:
>
> On Fri, Sep 18, 2015 at 3:44 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> > So I assume that if we have
> >
> > int X = 0;
> > atomic_t Y = ATOMIC_INIT(0);
> >
> > void w(void)
> > {
> > X = 1;
> > atomic_inc_return(&Y);
> > }
> >
> > then
> >
> > void r(void)
> > {
> > if (atomic_read_ctrl(&Y))
> > BUG_ON(X == 0);
> > }
> >
> > should be correct? Why?
> >
> > If not then I am even more confused.
>
> This not correct,

Good. because I wasn't able to understand why this could work.

> // thread 1
> X = 1;
> atomic_inc_return(&Y);
>
> // thread 2
> if (atomic_read_ctrl(&Y)) {
> X = 2;
> BUG_ON(X == 2);
> }

Thanks. This makes perfect sense to me.

And then I agree, atomic_read_ctrl() in put_pid() should fix the
theoretical problem.

Perhaps we can add this example to memory-barriers.txt... Although
perhaps it already explains/documents this case. I am afraid to open
it, it is huge and changes too often so every time it looks like a
new document to me ;)

Oleg.



\
 
 \ /
  Last update: 2015-09-18 17:21    [W:0.125 / U:0.128 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site