pthread_mutex_trylock() should never block
is at rambler-co.ru
Sat Dec 6 09:51:44 PST 2003
The current pthread_mutex_trylock() implementation in both libpthread (libkse)
and libthr can block if mutex is locked by another thread.
libphtread calls THR_LOCK_ACQUIRE() and it can be blocked.
libthr's pthread_mutex_trylock() is too heavy - it calls 3 syscalls:
sigprocmask()/umtx_lock()/sigprocmask() and can be blocked too.
[ 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 pthread_mutex_trylock() function will fail if:
The mutex could not be acquired because it was already locked.
[ ... ]
The pthread_mutex_lock() function may fail if:
The current thread already owns the mutex.
More information about the freebsd-threads