[clang-format] Rename ExportBlockIndentation -> IndentExportBlock (#123493)
[llvm-project.git] / compiler-rt / test / tsan / pthread_mutex_clocklock.cpp
blob63d329928080de3aa310d92fbfc928c2f584bc74
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // REQUIRES: glibc-2.30
3 #include <pthread.h>
4 #include <stdio.h>
6 pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
7 struct timespec ts = {0};
9 void *tfunc(void *p) {
10 if (!pthread_mutex_trylock(&m)) {
11 puts("Second thread could not lock mutex");
12 pthread_mutex_unlock(&m);
14 return p;
17 int main() {
18 if (!pthread_mutex_clocklock(&m, CLOCK_REALTIME, &ts)) {
19 pthread_t thr;
20 pthread_create(&thr, 0, tfunc, 0);
21 pthread_join(thr, 0);
22 pthread_mutex_unlock(&m);
23 } else
24 puts("Failed to lock mutex");
25 fprintf(stderr, "PASS\n");
28 // CHECK-NOT: WARNING: ThreadSanitizer: unlock of an unlocked mutex
29 // CHECK: PASS