Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / signal_sync.cpp
blobb529a1859f52a6c160ba73dede9efeeb52d58222
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // UNSUPPORTED: darwin
3 #include "test.h"
4 #include <signal.h>
5 #include <sys/types.h>
6 #include <sys/time.h>
7 #include <errno.h>
9 volatile int X;
11 static void handler(int sig) {
12 (void)sig;
13 if (X != 42)
14 printf("bad");
17 static void* thr(void *p) {
18 for (int i = 0; i != 1000; i++)
19 usleep(1000); // process signals
20 return 0;
23 int main() {
24 const int kThreads = 10;
25 pthread_t th[kThreads];
26 for (int i = 0; i < kThreads; i++)
27 pthread_create(&th[i], 0, thr, 0);
29 X = 42;
31 struct sigaction act = {};
32 act.sa_handler = &handler;
33 if (sigaction(SIGPROF, &act, 0)) {
34 perror("sigaction");
35 exit(1);
38 itimerval t;
39 t.it_value.tv_sec = 0;
40 t.it_value.tv_usec = 10;
41 t.it_interval = t.it_value;
42 if (setitimer(ITIMER_PROF, &t, 0)) {
43 perror("setitimer");
44 exit(1);
47 for (int i = 0; i < kThreads; i++)
48 pthread_join(th[i], 0);
50 fprintf(stderr, "DONE\n");
51 return 0;
54 // CHECK-NOT: WARNING: ThreadSanitizer:
55 // CHECK: DONE
56 // CHECK-NOT: WARNING: ThreadSanitizer: