Re: Safely giving up a lock before sleeping

Manfred Spraul (manfred@colorfullife.com)
Tue, 24 Jul 2001 17:20:06 +0200


> 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
(wait_event_lock_irq)

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

--
    Manfred

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/