[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / compiler-rt / test / tsan / signal_thread2.cpp
blob165055e224a9ecf21bf4d259771c49cc2def0fd4
1 // RUN: %clangxx_tsan %s -o %t && %run %t 2>&1 | FileCheck %s
2 // UNSUPPORTED: darwin
4 // FIXME: Very flaky on PPC with COMPILER_RT_DEBUG.
5 // https://github.com/google/sanitizers/issues/1792
6 // UNSUPPORTED: !compiler-rt-optimized && ppc
8 // Test case for https://github.com/google/sanitizers/issues/1540
10 #include <errno.h>
11 #include <pthread.h>
12 #include <signal.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <sys/time.h>
16 #include <sys/types.h>
17 #include <unistd.h>
19 volatile int X;
21 static void handler(int sig) {
22 (void)sig;
23 if (X != 0)
24 printf("bad");
27 static void *thr1(void *p) {
28 sleep(1);
29 return 0;
32 static void *thr(void *p) {
33 pthread_t th[10];
34 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
35 pthread_create(&th[i], 0, thr1, 0);
36 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
37 pthread_join(th[i], 0);
38 return 0;
41 int main() {
42 struct sigaction act = {};
43 act.sa_handler = &handler;
44 if (sigaction(SIGPROF, &act, 0)) {
45 perror("sigaction");
46 exit(1);
49 itimerval t;
50 t.it_value.tv_sec = 0;
51 t.it_value.tv_usec = 10;
52 t.it_interval = t.it_value;
53 if (setitimer(ITIMER_PROF, &t, 0)) {
54 perror("setitimer");
55 exit(1);
58 pthread_t th[100];
59 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
60 pthread_create(&th[i], 0, thr, 0);
61 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
62 pthread_join(th[i], 0);
64 fprintf(stderr, "DONE\n");
65 return 0;
68 // CHECK-NOT: WARNING: ThreadSanitizer:
69 // CHECK: DONE
70 // CHECK-NOT: WARNING: ThreadSanitizer: