[lkml]   [1999]   [Mar]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: 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

write_lock(&x); <------ (1)
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
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:50    [W:0.054 / U:2.672 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site