Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 2 | #include "test.h" |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 3 | #include <signal.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/time.h> |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 6 | #include <errno.h> |
| 7 | |
| 8 | volatile int X; |
| 9 | |
| 10 | static void handler(int sig) { |
| 11 | (void)sig; |
| 12 | if (X != 42) |
| 13 | printf("bad"); |
| 14 | } |
| 15 | |
| 16 | static void* thr(void *p) { |
| 17 | for (int i = 0; i != 1000; i++) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 18 | usleep(1000); // process signals |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | int main() { |
| 23 | const int kThreads = 10; |
| 24 | pthread_t th[kThreads]; |
| 25 | for (int i = 0; i < kThreads; i++) |
| 26 | pthread_create(&th[i], 0, thr, 0); |
| 27 | |
| 28 | X = 42; |
| 29 | |
| 30 | struct sigaction act = {}; |
| 31 | act.sa_handler = &handler; |
| 32 | if (sigaction(SIGPROF, &act, 0)) { |
| 33 | perror("sigaction"); |
| 34 | exit(1); |
| 35 | } |
| 36 | |
| 37 | itimerval t; |
| 38 | t.it_value.tv_sec = 0; |
| 39 | t.it_value.tv_usec = 10; |
| 40 | t.it_interval = t.it_value; |
| 41 | if (setitimer(ITIMER_PROF, &t, 0)) { |
| 42 | perror("setitimer"); |
| 43 | exit(1); |
| 44 | } |
| 45 | |
| 46 | for (int i = 0; i < kThreads; i++) |
| 47 | pthread_join(th[i], 0); |
| 48 | |
| 49 | fprintf(stderr, "DONE\n"); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | // CHECK-NOT: WARNING: ThreadSanitizer: |
| 54 | // CHECK: DONE |
| 55 | // CHECK-NOT: WARNING: ThreadSanitizer: |