From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <62412e4ba21aba9b056860657c24927d@ladd.quanstro.net> References: <62412e4ba21aba9b056860657c24927d@ladd.quanstro.net> Date: Thu, 24 Feb 2011 23:46:42 -0500 Message-ID: Subject: Re: [9fans] sleep/wakeup bug? From: Russ Cox To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Cc: erik quanstrom Content-Type: text/plain; charset=UTF-8 Topicbox-Message-UUID: b44ff59a-ead6-11e9-9d60-3106f5b1d025 On Thu, Feb 24, 2011 at 5:01 PM, erik quanstrom 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