blob: b529a1859f52a6c160ba73dede9efeeb52d58222 [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08002// UNSUPPORTED: darwin
Stephen Hines86277eb2015-03-23 12:06:32 -07003#include "test.h"
Stephen Hines6d186232014-11-26 17:56:19 -08004#include <signal.h>
5#include <sys/types.h>
6#include <sys/time.h>
Stephen Hines6d186232014-11-26 17:56:19 -08007#include <errno.h>
8
9volatile int X;
10
11static void handler(int sig) {
12 (void)sig;
13 if (X != 42)
14 printf("bad");
15}
16
17static void* thr(void *p) {
18 for (int i = 0; i != 1000; i++)
Stephen Hines86277eb2015-03-23 12:06:32 -070019 usleep(1000); // process signals
Stephen Hines6d186232014-11-26 17:56:19 -080020 return 0;
21}
22
23int main() {
24 const int kThreads = 10;
25 pthread_t th[kThreads];
26 for (int i = 0; i < kThreads; i++)
27 pthread_create(&th[i], 0, thr, 0);
28
29 X = 42;
30
31 struct sigaction act = {};
32 act.sa_handler = &handler;
33 if (sigaction(SIGPROF, &act, 0)) {
34 perror("sigaction");
35 exit(1);
36 }
37
38 itimerval t;
39 t.it_value.tv_sec = 0;
40 t.it_value.tv_usec = 10;
41 t.it_interval = t.it_value;
42 if (setitimer(ITIMER_PROF, &t, 0)) {
43 perror("setitimer");
44 exit(1);
45 }
46
47 for (int i = 0; i < kThreads; i++)
48 pthread_join(th[i], 0);
49
50 fprintf(stderr, "DONE\n");
51 return 0;
52}
53
54// CHECK-NOT: WARNING: ThreadSanitizer:
55// CHECK: DONE
56// CHECK-NOT: WARNING: ThreadSanitizer: