Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / Linux / mutex_robust.cpp
blob5ca5e70d49a71854ef30e9eefbb27030b7105451
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>
8 pthread_mutex_t m;
10 void *thr(void *p) {
11 pthread_mutex_lock(&m);
12 return 0;
15 int 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);
27 pthread_join(th, 0);
28 fprintf(stderr, "DONE\n");
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