pthread_mutex_trylock() should never block

Mike Makonnen mtm at identd.net
Wed Jan 28 08:50:55 PST 2004


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...

Cheers.
-- 
Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
mtm at identd.net | Fingerprint: 00E8 61BC 0D75 7FFB E4D3  6BF1 B239 D010 3215 D418
mtm at FreeBSD.Org| FreeBSD - Unleash the Daemon !


More information about the freebsd-threads mailing list