blob: 6ff19d3bd12092afad8575d1c8f9cc19d271145e [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
Stephen Hines86277eb2015-03-23 12:06:32 -07002#include "test.h"
Stephen Hines6d186232014-11-26 17:56:19 -08003#include <signal.h>
4#include <sys/types.h>
5#include <sys/time.h>
Stephen Hines6d186232014-11-26 17:56:19 -08006#include <errno.h>
7
8volatile int X;
9
10static void handler(int sig) {
11 (void)sig;
12 if (X != 42)
13 printf("bad");
14}
15
16static void* thr(void *p) {
17 for (int i = 0; i != 1000; i++)
Stephen Hines86277eb2015-03-23 12:06:32 -070018 usleep(1000); // process signals
Stephen Hines6d186232014-11-26 17:56:19 -080019 return 0;
20}
21
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: