Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / signal_pause.cpp
blobcbcef9491e9e4d6d7e03667373b99e2f729e1f06
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Test that pause loop handles signals.
5 #include "test.h"
6 #include <signal.h>
7 #include <errno.h>
9 void handler(int signum) {
10 write(2, "DONE\n", 5);
11 _exit(0);
14 void *thread(void *arg) {
15 for (;;)
16 pause();
17 return 0;
20 int 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;
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;
35 // CHECK: DONE