Re: Safely giving up a lock before sleeping

From: Manfred Spraul (
Date: Tue Jul 24 2001 - 10:20:06 EST

> If I implement this by calling spin_unlock_irqrestore() immediately
> followed by interruptible_sleep_on(), then I have a race condition
> where I could release the lock and immediately have a bottom half
> handler on another processor grab it, put data in the queue, and wake
> the wait queue. My original (user-side) process then happily goes
> to sleep, unaware that new information is available.

DO NOT use sleep_on in new code.
The correct replacement is wait_event() in <linux/wait.h> if the
spinlock is a normal (i.e. non-irq) spinlock.

Your spinlock is probably a spin_lock_irq() or spin_lock_bh() lock, then
you must build your own wait_event() wrapper.
check <linux/raid/md_k.h> for a wrapper with spin_lock_irq

The mouse driver sample in linux/documentation also explains the correct
way to release a lock and schedule.


- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to More majordomo info at Please read the FAQ at

This archive was generated by hypermail 2b29 : Tue Jul 31 2001 - 21:00:16 EST