From owner-cvs-all Mon Mar 17 11:14:40 2003 Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ADA5037B405 for ; Mon, 17 Mar 2003 11:14:33 -0800 (PST) Received: from mail.speakeasy.net (mail17.speakeasy.net [216.254.0.217]) by mx1.FreeBSD.org (Postfix) with ESMTP id 318D543FBD for ; Mon, 17 Mar 2003 11:14:28 -0800 (PST) (envelope-from jhb@FreeBSD.org) Received: (qmail 9288 invoked from network); 17 Mar 2003 19:14:33 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) by mail17.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 17 Mar 2003 19:14:33 -0000 Received: from laptop.baldwin.cx (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.12.8/8.12.8) with ESMTP id h2HJEPOv068866; Mon, 17 Mar 2003 14:14:25 -0500 (EST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.2 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200303150347.h2F3lLjK069888@freefall.freebsd.org> Date: Mon, 17 Mar 2003 14:14:45 -0500 (EST) From: John Baldwin To: David Xu Subject: Re: cvs commit: src/lib/libpthread/thread thr_rwlock.c Cc: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 15-Mar-2003 David Xu wrote: > This design prevents a thread to get a reader lock recursively when > there is a writter blocked on a rwlock. You didn't say that that was your reason earlier, and you didn't update the comment you rendered obsolete. To me this means you don't fully grasp the reasons behind the earlier code. If you don't keep track of holders of read locks and allow recursive read locks, then yes, you can get into a deadlock. This is why the in-kernel sx locks don't use this same algorithm at the moment. However, a more complete log message or a follow up should explain the reasons you are doing things and should not leave rotted comments around. > ----- Original Message ----- > From: "John Baldwin" > To: "John Baldwin" > Cc: ; ; ; "David Xu" > > Sent: Saturday, March 15, 2003 3:31 AM > Subject: RE: cvs commit: src/lib/libpthread/thread thr_rwlock.c > > >> >> On 14-Mar-2003 John Baldwin wrote: >> > >> > On 14-Mar-2003 David Xu wrote: >> >> davidxu 2003/03/13 17:02:47 PST >> >> >> >> FreeBSD src repository >> >> >> >> Modified files: >> >> lib/libpthread/thread thr_rwlock.c >> >> Log: >> >> Fix a bug in rwlock. When a rwlock was locked by reader threads, a >> >> writter thread can block reader threads to get read lock. >> > >> > That's not a bug. That is a very common way of implementing reader >> > writer locks. The idea is that if a writer is waiting for the lock >> > you make later read requests wait for the lock so that they don't >> > starve the writer. This is how Solaris rw locks work for example. >> > The in-kernel sx locks don't currently work that way, but that >> > may change at some point in the future. For more discussion on why >> > Solaris chose this route, go find a copy of Solaris Internals. >> > >> > You probably should revert this and find out if this was an >> > intentional design decision rather than a "bug". >> >> Looking at the diff a bit more: >> >> @@ -157,7 +157,7 @@ >> return(ret); >> >> /* give writers priority over readers */ >> - while (prwlock->blocked_writers || prwlock->state < 0) { >> + while (prwlock->state < 0) { >> ret = pthread_cond_wait(&prwlock->read_signal, &prwlock->lock); >> >> if (ret != 0) { >> >> The comment above the while loop seems to indicate that this was >> indeed a design choice. As a result of this change the comment no >> longer applies. Please revert. >> >> -- >> >> John Baldwin <>< http://www.FreeBSD.org/~jhb/ >> "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message