1// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
3
4void *Thread(void *x) {
5 pthread_mutex_lock(mutex: (pthread_mutex_t*)x);
6 pthread_mutex_unlock(mutex: (pthread_mutex_t*)x);
7 barrier_wait(barrier: &barrier);
8 return 0;
9}
10
11int main() {
12 barrier_init(barrier: &barrier, count: 2);
13 pthread_mutex_t Mtx;
14 pthread_mutex_init(mutex: &Mtx, mutexattr: 0);
15 pthread_t t;
16 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: &Mtx);
17 barrier_wait(barrier: &barrier);
18 pthread_mutex_destroy(mutex: &Mtx);
19 pthread_join(th: t, thread_return: 0);
20 return 0;
21}
22
23// CHECK: WARNING: ThreadSanitizer: data race
24

source code of compiler-rt/test/tsan/race_on_mutex2.c