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