9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Russ Cox <rsc@swtch.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Cc: erik quanstrom <quanstro@quanstro.net>
Subject: Re: [9fans] sleep/wakeup bug?
Date: Thu, 24 Feb 2011 23:46:42 -0500	[thread overview]
Message-ID: <AANLkTin2do0vgpx53211VSQSN=SS9aVHPS4iwy=zocF4@mail.gmail.com> (raw)
In-Reply-To: <62412e4ba21aba9b056860657c24927d@ladd.quanstro.net>

On Thu, Feb 24, 2011 at 5:01 PM, erik quanstrom <quanstro@quanstro.net> wrote:
> /sys/doc/sleep.ps says that sleep/wakeup are atomic.
> in concrete terms, i take this to mean that if sleep
> has returned, wakeup will no longer be in its critical
> section.

it means only that if sleep finds f(arg) to be false,
then sleep is guaranteed not to miss a wakeup
called after f(arg) has been established to be true.
in short it means no missed wakeups.

sleep may in various conditions wake up spuriously,
and it won't go to sleep at all if it finds f(arg) to be true.

assuming a tight 1:1 coupling between sleep and
wakeup is a recipe for trouble.  even if your change
fixes one possible race (i didn't bother to see what changed),
you still have to deal with

cpu1:
    decide to call sleep
    call sleep

cpu2:
    decide to call wakeup

cpu1:
    sleep checks f(arg), finds true
    sleep returns
    frees whatever

cpu2:
    call wakeup
    wakeup runs on freed memory

these races are inherent to the definition of sleep and
wakeup.  it doesn't mean what you need it to mean
to free memory immediately after sleeping on it.

russ


  reply	other threads:[~2011-02-25  4:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-24 22:01 erik quanstrom
2011-02-25  4:46 ` Russ Cox [this message]
2011-02-25  9:46 ` Richard Miller
2011-02-25  5:26 erik quanstrom
2011-02-25  5:47 ` Russ Cox
2011-02-25  5:53   ` erik quanstrom
2011-02-25  6:01     ` Russ Cox
2011-02-25  6:12       ` erik quanstrom
     [not found]       ` <2808a9fa079bea86380a8d52be67b980@coraid.com>
     [not found]         ` <AANLkTi=4_=++Tm2a9Jq9jSzqUSexkW-ZjM-38oD_bS1y@mail.gmail.com>
     [not found]           ` <40925e8f64489665bd5bd6ca743400ea@coraid.com>
2011-02-25  6:51             ` Russ Cox
2011-02-25  7:13               ` erik quanstrom
2011-02-25 14:44                 ` Russ Cox
2011-02-25  8:37               ` Sape Mullender
2011-02-25  9:18                 ` Bakul Shah
2011-02-25 14:57               ` Charles Forsyth
2011-02-25 16:09               ` Venkatesh Srinivas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTin2do0vgpx53211VSQSN=SS9aVHPS4iwy=zocF4@mail.gmail.com' \
    --to=rsc@swtch.com \
    --cc=9fans@9fans.net \
    --cc=quanstro@quanstro.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).