Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jan 2004 19:11:52 +0300
From:      Mike Makonnen <mtm@identd.net>
To:        Daniel Eischen <eischen@vigrid.com>
Cc:        Peter Kostouros <kpeter@melbpc.org.au>
Subject:   Re: pthread_mutex_trylock() should never block
Message-ID:  <20040129161152.GA1070@mobile.acsolutions.com>
In-Reply-To: <Pine.GSO.4.10.10401290855160.29384-100000@pcnet5.pcnet.com>
References:  <20040129082122.GA1439@mobile.acsolutions.com> <Pine.GSO.4.10.10401290855160.29384-100000@pcnet5.pcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 !



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040129161152.GA1070>