From owner-freebsd-threads@FreeBSD.ORG Thu Jan 29 08:12:20 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C6DFB16A4CE for ; Thu, 29 Jan 2004 08:12:20 -0800 (PST) Received: from telecom.net.et (sparrow.telecom.net.et [213.55.64.38]) by mx1.FreeBSD.org (Postfix) with ESMTP id A2AE143D31 for ; Thu, 29 Jan 2004 08:12:04 -0800 (PST) (envelope-from mtm@identd.net) Received: from [213.55.66.193] (HELO pool-151-200-10-97.res.east.verizon.net) by telecom.net.et (CommuniGate Pro SMTP 3.4.8) with ESMTP-TLS id 35417445; Thu, 29 Jan 2004 19:06:24 +0300 Received: from mobile.acsolutions.com (localhost [127.0.0.1]) ESMTP id i0TGBt41001107; Thu, 29 Jan 2004 19:11:57 +0300 (EAT) (envelope-from mtm@mobile.acsolutions.com) Received: (from mtm@localhost) by mobile.acsolutions.com (8.12.10/8.12.10/Submit) id i0TGBrs2001106; Thu, 29 Jan 2004 19:11:53 +0300 (EAT) (envelope-from mtm) Date: Thu, 29 Jan 2004 19:11:52 +0300 From: Mike Makonnen To: Daniel Eischen Message-ID: <20040129161152.GA1070@mobile.acsolutions.com> References: <20040129082122.GA1439@mobile.acsolutions.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD/5.2-CURRENT (i386) cc: threads@FreeBSD.org cc: Peter Kostouros Subject: Re: pthread_mutex_trylock() should never block X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jan 2004 16:12:20 -0000 On Thu, Jan 29, 2004 at 09:06:42AM -0500, Daniel Eischen wrote: > > > > EDEADLK is returned by pthread_mutex_lock() only on error > > checking mutexes that would otherwise deadlock if they were not error > > checking. Since pthread_mutex_trylock() must return immediately whether > > the mutex is error-checking or not, I think for consistency sake it should > > return EBUSY regardless of what type of mutex it is operating on. Also, > > the 'ERRORS' section lists EDEADLK as a _possible_ return value only for > > pthread_mutex_lock(). > > I looked at "pthread_mutex_trylock() function shall be equivalent to > pthread_mutex_lock()" and inferred that it even meant returned > errors should be equivalent. > > > I'm not a standards expert but I think it is permissable for an > > implementation to return EDEADLK from pthread_mutex_trylock(). However, > > I think it's better to always return EBUSY, rather than EDEADLK in > > some cases and EBUSY in others. > > Well, anything that relies on pthread_mutex_trylock() != EBUSY > to mean that the function worked is broken (clearly 0 is the > only return that means success). And if the application wants > to know if the current thread has the mutex locked, then > returning EBUSY doesn't tell you anything, whereas EDEADLK > does. Yeah, I know, applications should keep track of which > mutexes they have locked! > Agreed :-) Cheers. -- Mike Makonnen | GPG-KEY: http://www.identd.net/~mtm/mtm.asc mtm@identd.net | Fingerprint: 00E8 61BC 0D75 7FFB E4D3 6BF1 B239 D010 3215 D418 mtm@FreeBSD.Org| FreeBSD - Unleash the Daemon !