Bug in kern_umtx.c -- read-write locks
David Xu
davidxu at freebsd.org
Wed Feb 3 04:05:03 UTC 2010
Justin Teller wrote:
> I was working on a highly threaded app (125+ threads) that was using
> the pthread rw locks, and we were stalling at strange times. After a
> lot of debugging in our app, we found that a call to
> pthread_rwlock_wrlock() would sometimes never return -- it seemed like
> a wakeup was lost. After we convinced ourselves the bug wasn't in the
> app's locking code, I started digging into the kernel. I found that
> there is an issue where a wakeup can be "lost" when a thread goes to
> sleep calling pthread_rwlock_wrlock. The issue is in the file
> kern_umtx.c in the function do_rw_wrlock(): the code busies the lock
> before sleeping, but when it tries to set the waiters bit, it's
> looking at at old value (from the "try-lock" just before the busy).
> This allows a race where a thread can go to sleep w/o setting the
> waiters bit. Then the last thread to unlock won't wakeup the sleeping
> thread. The patch below (based off of 8.0 release) fixes my problem
> for the write lock and should fix the complimentary issue in
> do_rw_rdlock.
>
> <snip>
Committed, thanks!
More information about the freebsd-current
mailing list