On Thu, Feb 24, 2011 at 5:01 PM, erik quanstrom <quans...@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 via email to