1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 #include "test.h" 3 #include <signal.h> 4 #include <sys/types.h> 5 #include <sys/time.h> 6 #include <errno.h> 7 8 volatile int X; 9 handler(int sig)10static void handler(int sig) { 11 (void)sig; 12 if (X != 42) 13 printf("bad"); 14 } 15 thr(void * p)16static void* thr(void *p) { 17 for (int i = 0; i != 1000; i++) 18 usleep(1000); // process signals 19 return 0; 20 } 21 main()22int 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: 56