From owner-freebsd-current@FreeBSD.ORG Wed Feb 3 04:05:03 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D81401065676 for ; Wed, 3 Feb 2010 04:05:03 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id C7D268FC15; Wed, 3 Feb 2010 04:05:03 +0000 (UTC) Received: from apple.my.domain (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o13452g2071882; Wed, 3 Feb 2010 04:05:03 GMT (envelope-from davidxu@freebsd.org) Message-ID: <4B68F5EE.9060606@freebsd.org> Date: Wed, 03 Feb 2010 12:05:02 +0800 From: David Xu User-Agent: Thunderbird 2.0.0.9 (X11/20080612) MIME-Version: 1.0 To: Justin Teller References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org Subject: Re: Bug in kern_umtx.c -- read-write locks X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2010 04:05:03 -0000 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. > > Committed, thanks!