1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 // REQUIRES: glibc-2.30 3 #include <pthread.h> 4 #include <stdio.h> 5 6 pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; 7 struct timespec ts = {0}; 8 tfunc(void * p)9void *tfunc(void *p) { 10 if (!pthread_mutex_trylock(&m)) { 11 puts("Second thread could not lock mutex"); 12 pthread_mutex_unlock(&m); 13 } 14 return p; 15 } 16 main()17int main() { 18 if (!pthread_mutex_clocklock(&m, CLOCK_REALTIME, &ts)) { 19 pthread_t thr; 20 pthread_create(&thr, 0, tfunc, 0); 21 pthread_join(thr, 0); 22 pthread_mutex_unlock(&m); 23 } else 24 puts("Failed to lock mutex"); 25 fprintf(stderr, "PASS\n"); 26 } 27 28 // CHECK-NOT: WARNING: ThreadSanitizer: unlock of an unlocked mutex 29 // CHECK: PASS 30