Source: libc0.3-dev
Version: 2.24-8
Severity: important

According to the documentation (man page) for pthread_mutex_trylock:

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.

RETURN VALUE
  The pthread_mutex_trylock() function shall fail if:

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

Here is a short test program


#include <pthread.h>
#include <stdio.h>
#include <errno.h>

int main() {
  pthread_mutex_t m;
  int i;
  printf("%s: %i\n", "EBUSY", EBUSY);
  printf("%s: %i\n", "EAGAIN", EAGAIN);

  i = pthread_mutex_init(&m, NULL);
  printf("%s: %i\n", "init", i);
  i = pthread_mutex_lock(&m);
  printf("%s: %i\n", "lock", i);
  i = pthread_mutex_trylock(&m);
  printf("%s: %i\n", "trylock", i);
  i = pthread_mutex_unlock(&m);
  printf("%s: %i\n", "unlock", i);
  i = pthread_mutex_destroy(&m);
  printf("%s: %i\n", "destroy", i);
}


On Linux this behaves according to the documentation:

EBUSY: 16
EAGAIN: 11
init: 0
lock: 0
trylock: 16
unlock: 0
destroy: 0

I.e. the trylock on the already locked mutex returns EBUSY.

On Hurd the following happens:

EBUSY: 1073741840
EAGAIN: 1073741859
init: 0
lock: 0
trylock: -1
unlock: 0
destroy: 0

I.e. the trylock on the already locked mutex returns -1 instead.

This causes programs using GLib to abort execution:

GLib (gthread-posix.c): Unexpected error from C library during
'pthread_mutex_trylock': Error in unknown error system: FFFFFFFF. 
Aborting.
Aborted

        Mattias

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to