Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / signal_thread.cpp
blobaa91d1ddeb101cc01aa4e4a4db21fd61479e2de5
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // UNSUPPORTED: darwin
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <signal.h>
7 #include <sys/types.h>
8 #include <sys/time.h>
9 #include <unistd.h>
10 #include <errno.h>
12 volatile int X;
14 static void handler(int sig) {
15 (void)sig;
16 if (X != 0)
17 printf("bad");
20 static void* thr(void *p) {
21 return 0;
24 int main() {
25 struct sigaction act = {};
26 act.sa_handler = &handler;
27 if (sigaction(SIGPROF, &act, 0)) {
28 perror("sigaction");
29 exit(1);
32 itimerval t;
33 t.it_value.tv_sec = 0;
34 t.it_value.tv_usec = 10;
35 t.it_interval = t.it_value;
36 if (setitimer(ITIMER_PROF, &t, 0)) {
37 perror("setitimer");
38 exit(1);
41 for (int i = 0; i < 10000; i++) {
42 pthread_t th;
43 pthread_create(&th, 0, thr, 0);
44 pthread_join(th, 0);
47 fprintf(stderr, "DONE\n");
48 return 0;
51 // CHECK-NOT: WARNING: ThreadSanitizer:
52 // CHECK: DONE
53 // CHECK-NOT: WARNING: ThreadSanitizer: