[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#788999: pthread_mutex_trylock on x86 with lock elision is broken



Package: libc6
Version: 2.19-18
Severity: important

The released version of glibc in jessie incorrectly returns a failure
from pthread_mutex_destroy when pthread_mutex_trylock is used on my
machine (which is amd64). It might only happen on hardware with lock
elision support. The upstream patch at
https://sourceware.org/ml/libc-alpha/2014-12/msg00228.html fixes the
problem.

The sysdeps/unix/sysv/linux/x86/force-elision.h file in the patch is
named nptl/sysdeps/unix/sysv/linux/x86/force-elision.h in Debian's
version and the sysdeps/unix/sysv/linux/s390/force-elision.h file
doesn't exist.

Here's a simple test program which demonstrates the problem:
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

int main() {
  pthread_mutex_t mutex;
  assert(pthread_mutex_init(&mutex, NULL) == 0);
  assert(pthread_mutex_trylock(&mutex) == 0);
  assert(pthread_mutex_unlock(&mutex) == 0);
  const int result = pthread_mutex_destroy(&mutex);
  if (result == 0) {
    printf("Looks good\n");
  } else {
    printf("Bug!\n");
  }
}

It prints "Bug!" with unpatched libc6 2.19-18 and "Looks good" once I
install a version with the patch applied.

I think https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=759197 has
the same root cause.

Thanks,
Brian Silverman


Reply to: