Messages in this thread | | | Date | Sun, 14 Mar 1999 12:37:42 +0100 (CET) | From | Ingo Molnar <> | Subject | Re: sleeping while holding a rwspinlock? |
| |
On Sun, 14 Mar 1999, Tigran Aivazian wrote:
> I ask plainly - can I sleep while having read-locked rwspinlock? > > If yes, thank you. > If no, I will update Documentation/spinlocks.txt and send you a patch for > approval.
The Linux rule is that you must not sleep while holding any spinlock. spinlocks are 'light and short operations' (in theory), and the Linux locking architecture relies on us not scheduling during held locks. (we'd get into deadlocks easily if we allowed this, semaphores should be used in places where complex locking has to be done)
here is one sample deadlock scenario:
P(A) on CPU0 P(B) on CPU1
read_lock(&x); schedule(); write_lock(&x); <------ (1) ... write_unlock(&x); wakeup(P(A)); <------ (2)
we never get to (2) because (1) loops infinitely. (until all read locks are released.)
at some point in 2.1 we even had an 'inbalanced spinlocks in schedule()' debugging line in sched.c because we had a couple of such bugs.
-- mingo
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |