brintos

brintos / llvm-project-archived public Read only

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