pthread_mutex_trylock() should never block

Daniel Eischen eischen at vigrid.com
Sat Dec 6 10:40:08 PST 2003


On Sat, 6 Dec 2003, Daniel Eischen wrote:

> On Sat, 6 Dec 2003, Igor Sysoev wrote:
> > 
> > SUSv2 states:
> > [ http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_mutex_lock.html ]
> > 
> > --------
> > The function pthread_mutex_trylock() is identical 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 returns immediately.
> 
> The low-level locks are necessary (at least in libpthread implementation)
> to safely test the mutex for ownership.

And not only that, but the low-level locks are also necessary to take
the mutex if it is not owned.

-- 
Dan Eischen



More information about the freebsd-threads mailing list