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 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 2 | // UNSUPPORTED: darwin |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 3 | #include "test.h" |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 4 | #include <signal.h> |
| 5 | #include <sys/types.h> |
| 6 | #include <sys/time.h> |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 7 | #include <errno.h> |
| 8 | |
| 9 | volatile int X; |
| 10 | |
| 11 | static void handler(int sig) { |
| 12 | (void)sig; |
| 13 | if (X != 42) |
| 14 | printf("bad"); |
| 15 | } |
| 16 | |
| 17 | static void* thr(void *p) { |
| 18 | for (int i = 0; i != 1000; i++) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 19 | usleep(1000); // process signals |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 20 | return 0; |
| 21 | } |
| 22 | |
| 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); |
| 28 | |
| 29 | X = 42; |
| 30 | |
| 31 | struct sigaction act = {}; |
| 32 | act.sa_handler = &handler; |
| 33 | if (sigaction(SIGPROF, &act, 0)) { |
| 34 | perror("sigaction"); |
| 35 | exit(1); |
| 36 | } |
| 37 | |
| 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); |
| 45 | } |
| 46 | |
| 47 | for (int i = 0; i < kThreads; i++) |
| 48 | pthread_join(th[i], 0); |
| 49 | |
| 50 | fprintf(stderr, "DONE\n"); |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | // CHECK-NOT: WARNING: ThreadSanitizer: |
| 55 | // CHECK: DONE |
| 56 | // CHECK-NOT: WARNING: ThreadSanitizer: |