Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / Linux / thread_timedjoin.c
blob1d3f1098ece753e2809b7888fd41909229a616b7
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #define _GNU_SOURCE
3 #include "../test.h"
4 #include <errno.h>
6 int var;
8 void *Thread(void *x) {
9 barrier_wait(&barrier);
10 var = 1;
11 return 0;
14 static void check(int res, int expect) {
15 if (res != expect) {
16 fprintf(stderr, "Unexpected result of pthread_timedjoin_np: %d\n", res);
17 exit(1);
21 int main() {
22 barrier_init(&barrier, 2);
23 pthread_t t;
24 pthread_create(&t, 0, Thread, 0);
25 struct timespec ts;
26 clock_gettime(CLOCK_REALTIME, &ts);
27 check(pthread_timedjoin_np(t, 0, &ts), ETIMEDOUT);
28 barrier_wait(&barrier);
29 clock_gettime(CLOCK_REALTIME, &ts);
30 ts.tv_sec += 10000;
31 check(pthread_timedjoin_np(t, 0, &ts), 0);
32 var = 2;
33 fprintf(stderr, "PASS\n");
34 return 0;
37 // CHECK-NOT: WARNING: ThreadSanitizer: data race
38 // CHECK-NOT: WARNING: ThreadSanitizer: thread leak
39 // CHECK: PASS