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
8pthread_mutex_t m;
9
10void *thr(void *p) {
11 pthread_mutex_lock(mutex: &m);
12 return 0;
13}
14
15int main() {
16 pthread_mutexattr_t a;
17 pthread_mutexattr_init(attr: &a);
18 pthread_mutexattr_setrobust(attr: &a, robustness: PTHREAD_MUTEX_ROBUST);
19 pthread_mutex_init(mutex: &m, mutexattr: &a);
20 pthread_t th;
21 pthread_create(newthread: &th, attr: 0, start_routine: thr, arg: 0);
22 sleep(seconds: 1);
23 if (pthread_mutex_lock(mutex: &m) != EOWNERDEAD) {
24 fprintf(stderr, format: "not EOWNERDEAD\n");
25 exit(status: 1);
26 }
27 pthread_join(th: th, thread_return: 0);
28 fprintf(stderr, format: "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

source code of compiler-rt/test/tsan/Linux/mutex_robust.cpp