From owner-freebsd-threads@FreeBSD.ORG Wed Jan 28 09:01:39 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 3DE9E16A4CE for ; Wed, 28 Jan 2004 09:01:39 -0800 (PST) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id EFF9743D58 for ; Wed, 28 Jan 2004 09:01:28 -0800 (PST) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.10/8.12.1) with ESMTP id i0SH1Riw010232; Wed, 28 Jan 2004 12:01:28 -0500 (EST) Date: Wed, 28 Jan 2004 12:01:27 -0500 (EST) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Mike Makonnen In-Reply-To: <20040128165031.GA3461@mobile.acsolutions.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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: Wed, 28 Jan 2004 17:01:39 -0000 On Wed, 28 Jan 2004, Mike Makonnen wrote: > On Sun, Dec 07, 2003 at 01:34:31AM -0500, Daniel Eischen wrote: > > > > The man page may not mention it, and that may be a bug, but I > > think a pthread_mutex_trylock() on a non-recursive mutex is allowed > > to return EDEADLK. > > > > http://www.opengroup.org/onlinepubs/007904975/functions/pthread_mutex_trylock.html > > > > If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error > > checking shall be provided. If a thread attempts to relock a > > mutex that it has already locked, an error shall be returned. > > If a thread attempts to unlock a mutex that it has not locked > > or a mutex which is unlocked, an error shall be returned. > > > > ... > > If you look further down in the spec you will see: > > The pthread_mutex_trylock() function shall be equivalent to > pthread_mutex_lock(), except that if the mutex object referenced > by mutex is currently locked (by any thread, including > the current thread), the call shall return immediately... Yes, but the implementation has to use internal locks to keep the mutex in a consistent state. There is no problem here. -- Dan Eischen