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