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