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> |
11 | |
12 | volatile int X; |
13 | |
14 | static void handler(int sig) { |
15 | (void)sig; |
16 | if (X != 0) |
17 | printf(format: "bad"); |
18 | } |
19 | |
20 | static void* thr(void *p) { |
21 | return 0; |
22 | } |
23 | |
24 | int main() { |
25 | struct sigaction act = {}; |
26 | act.sa_handler = &handler; |
27 | if (sigaction(SIGPROF, act: &act, oact: 0)) { |
28 | perror(s: "sigaction"); |
29 | exit(status: 1); |
30 | } |
31 | |
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, new: &t, old: 0)) { |
37 | perror(s: "setitimer"); |
38 | exit(status: 1); |
39 | } |
40 | |
41 | for (int i = 0; i < 10000; i++) { |
42 | pthread_t th; |
43 | pthread_create(newthread: &th, attr: 0, start_routine: thr, arg: 0); |
44 | pthread_join(th: th, thread_return: 0); |
45 | } |
46 | |
47 | fprintf(stderr, format: "DONE\n"); |
48 | return 0; |
49 | } |
50 | |
51 | // CHECK-NOT: WARNING: ThreadSanitizer: |
52 | // CHECK: DONE |
53 | // CHECK-NOT: WARNING: ThreadSanitizer: |
54 |