Date: Tue, 2 Feb 2010 21:16:29 -0800 From: Garrett Cooper <yanefbsd@gmail.com> To: David Xu <davidxu@freebsd.org> Cc: freebsd-current@freebsd.org, Justin Teller <justin.teller@gmail.com> Subject: Re: Bug in kern_umtx.c -- read-write locks Message-ID: <7d6fde3d1002022116v28d50f75me27e7208619e2a3c@mail.gmail.com> In-Reply-To: <4B68F5EE.9060606@freebsd.org> References: <c47019cc1002021207rc9ca100ga0dd865febdb0014@mail.gmail.com> <4B68F5EE.9060606@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Feb 2, 2010 at 8:05 PM, David Xu <davidxu@freebsd.org> wrote:
> 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. =A0After 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. =A0After we convinced ourselves the bug wasn't in the
>> app's locking code, I started digging into the kernel. =A0I found that
>> there is an issue where a wakeup can be "lost" when a thread goes to
>> sleep calling pthread_rwlock_wrlock. =A0The 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. =A0Then the last thread to unlock won't wakeup the sleeping
>> thread. =A0The 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.
>>
>> =A0<snip>
>
> Committed, thanks!
This might be the reason why the pthreaded application I was
working on was crashing when I had it spawn more than 100 threads (I
tried 2k and 20k simple, short-lived threads that used a basic mutex,
and it got into some deadlock state and bombed)... I'll see whether or
not this fixes my issue as well (but FWIW Linux sucked when I ran the
pthreaded app too and was busting up all over the place)...
Thanks!
-Garrett
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7d6fde3d1002022116v28d50f75me27e7208619e2a3c>
