1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
13 static int SignalPipeFd
[] = {-1, -1};
14 static int BlockingPipeFd
[] = {-1, -1};
16 static void Handler(int _
) { assert(write(SignalPipeFd
[1], ".", 1) == 1); }
18 static void *ThreadFunc(void *_
) {
20 assert(read(BlockingPipeFd
[0], &C
, sizeof(C
)) == 1);
26 alarm(60); // Kill the test if it hangs.
28 assert(pipe(SignalPipeFd
) == 0);
29 assert(pipe(BlockingPipeFd
) == 0);
32 sigemptyset(&act
.sa_mask
);
33 act
.sa_flags
= SA_RESTART
;
34 act
.sa_handler
= Handler
;
35 assert(sigaction(SIGUSR1
, &act
, 0) == 0);
38 assert(pthread_create(&Thr
, 0, ThreadFunc
, 0) == 0);
40 // Give the thread enough time to block in the read call.
43 // Signal the thread, this should run the signal handler and unblock the read
45 pthread_kill(Thr
, SIGUSR1
);
47 assert(read(SignalPipeFd
[0], &C
, 1) == 1);
49 // Unblock the thread and join it.
50 assert(write(BlockingPipeFd
[1], &C
, 1) == 1);
52 assert(pthread_join(Thr
, &_
) == 0);
54 fprintf(stderr
, "PASS\n");
58 // CHECK-NOT: WARNING: ThreadSanitizer: