1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 #include <pthread.h> 3 #include <stdlib.h> 4 #include <stdio.h> 5 #include <unistd.h> 6 #include <errno.h> 7 8 pthread_mutex_t m; 9 thr(void * p)10void *thr(void *p) { 11 pthread_mutex_lock(&m); 12 return 0; 13 } 14 main()15int main() { 16 pthread_mutexattr_t a; 17 pthread_mutexattr_init(&a); 18 pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST); 19 pthread_mutex_init(&m, &a); 20 pthread_t th; 21 pthread_create(&th, 0, thr, 0); 22 sleep(1); 23 if (pthread_mutex_lock(&m) != EOWNERDEAD) { 24 fprintf(stderr, "not EOWNERDEAD\n"); 25 exit(1); 26 } 27 pthread_join(th, 0); 28 fprintf(stderr, "DONE\n"); 29 } 30 31 // This is a correct code, and tsan must not bark. 32 // CHECK-NOT: WARNING: ThreadSanitizer 33 // CHECK-NOT: EOWNERDEAD 34 // CHECK: DONE 35 // CHECK-NOT: WARNING: ThreadSanitizer 36 37