pthread_mutex_trylock and glib-2

Stijn Hoop stijn at win.tue.nl
Mon Sep 6 21:58:11 PDT 2004


Hi,

thanks for digging at this!

On Mon, Sep 06, 2004 at 03:12:08PM -0700, Pascal Hofstee wrote:
> After a few hours of digging through both the glib-2 as well as the
> beep-media-player sources i finally managed to figure out why
> beep-media-player apprently crashes on startup when using libpthread,
> but not when using libc_r.
> 
> i filed a bugreport against this problem on bugzilla.gnome.org ... in
> the hope to get some feedback from glib-developers ...
> 
> http://bugzilla.gnome.org/show_bug.cgi?id=152009
> 
> The problem is with the actual return value of pthread_mutex_trylock
> returning EDEADLK instead of EBUSY.
> 
> from what i have been able to glance from this previous discussion
> regarding this particular subject
> (http://lists.freebsd.org/pipermail/freebsd-threads/2004-January/001539.html)
> 
> pthread_mutex_trylock should behave identical to pthread_mutex_lock
> except return immediately in case of a blocking mutex, which would
> suggest EDEADLK as a possible return value.

Well, according to

http://www.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_trylock.html

(linked from the discussion above), I would read this:

%%%

The pthread_mutex_trylock() function shall fail if:

[EBUSY]
    The mutex could not be acquired because it was already locked. 

The pthread_mutex_lock() function may fail if:

[EDEADLK]
    A deadlock condition was detected or the current thread already owns the mutex. 

%%%

as the glib developers apparently did -- namely that pthread_mutex_trylock
cannot return EDEADLK, only EBUSY. The fact that it is the current thread
that has already locked the mutex is only required to be detected by the
pthread_mutex_lock function. In other words, I agree with Mike Makonnen
in your quoted e-mail, but apparently the implementation does not.

In any case, modifying glib to also check for EDEADLK would probably be
appropriate.

--Stijn

-- 
I wish there was a knob on the TV to turn up the intelligence.  There's a knob
called `brightness', but it doesn't work."
		-- Gallagher
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20040907/46f6ecf1/attachment.bin


More information about the freebsd-hackers mailing list