summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2009-09-23 21:38:57 +0000
committerattilio <attilio@FreeBSD.org>2009-09-23 21:38:57 +0000
commita18d0e5adbe0bc91732fc822309261987789e3d3 (patch)
treeec20716798fdaee7731f2a928ff8700b493b83cd /lib/libthr
parent4f6b75d3582dc31a63fd718d187e6e266ffb2bbc (diff)
downloadFreeBSD-src-a18d0e5adbe0bc91732fc822309261987789e3d3.zip
FreeBSD-src-a18d0e5adbe0bc91732fc822309261987789e3d3.tar.gz
rwlock implemented from libthr need to fall through the 'hard path' and
query umtx also if the shared waiters bit is set on a shared lock. The writer starvation avoidance technique, infact, can lead to shared waiters on a shared lock which can bring to a missed wakeup and thus to a deadlock if the right bit is not checked (a notable case is the writers counterpart to be handled through expired timeouts). Fix that by checking for the shared waiters bit also when unlocking the shared locks. That bug was causing a reported MySQL deadlock. Many thanks go to Nick Esborn and his employer DesertNet which provided time and machines to identify and fix this issue. PR: thread/135673 Reported by: Nick Esborn <nick at desert dot net> Tested by: Nick Esborn <nick at desert dot net> Reviewed by: jeff
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_umtx.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libthr/thread/thr_umtx.h b/lib/libthr/thread/thr_umtx.h
index 41b5f96..a6e462e 100644
--- a/lib/libthr/thread/thr_umtx.h
+++ b/lib/libthr/thread/thr_umtx.h
@@ -171,8 +171,11 @@ _thr_rwlock_unlock(struct urwlock *rwlock)
for (;;) {
if (__predict_false(URWLOCK_READER_COUNT(state) == 0))
return (EPERM);
- if (!((state & URWLOCK_WRITE_WAITERS) && URWLOCK_READER_COUNT(state) == 1)) {
- if (atomic_cmpset_rel_32(&rwlock->rw_state, state, state-1))
+ if (!((state & (URWLOCK_WRITE_WAITERS |
+ URWLOCK_READ_WAITERS)) &&
+ URWLOCK_READER_COUNT(state) == 1)) {
+ if (atomic_cmpset_rel_32(&rwlock->rw_state,
+ state, state-1))
return (0);
state = rwlock->rw_state;
} else {
OpenPOWER on IntegriCloud