1// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2
3// Test that pause loop handles signals.
4
5#include "test.h"
6#include <signal.h>
7#include <errno.h>
8
9void handler(int signum) {
10 write(2, "DONE\n", 5);
11 _exit(0);
12}
13
14void *thread(void *arg) {
15 for (;;)
16 pause();
17 return 0;
18}
19
20int main(int argc, char** argv) {
21 struct sigaction act = {};
22 act.sa_handler = &handler;
23 if (sigaction(SIGUSR1, &act, 0)) {
24 fprintf(stderr, "sigaction failed %d\n", errno);
25 return 1;
26 }
27 pthread_t th;
28 pthread_create(&th, 0, thread, 0);
29 sleep(1); // give it time to block in pause
30 pthread_kill(th, SIGUSR1);
31 sleep(10); // signal handler must exit the process while we are here
32 return 0;
33}
34
35// CHECK: DONE
36