| 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 | |
| 9 | void handler(int signum) { |
| 10 | write(fd: 2, buf: "DONE\n" , n: 5); |
| 11 | _exit(status: 0); |
| 12 | } |
| 13 | |
| 14 | void *thread(void *arg) { |
| 15 | for (;;) |
| 16 | pause(); |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | int main(int argc, char** argv) { |
| 21 | struct sigaction act = {}; |
| 22 | act.sa_handler = &handler; |
| 23 | if (sigaction(SIGUSR1, act: &act, oact: 0)) { |
| 24 | fprintf(stderr, format: "sigaction failed %d\n" , errno); |
| 25 | return 1; |
| 26 | } |
| 27 | pthread_t th; |
| 28 | pthread_create(newthread: &th, attr: 0, start_routine: thread, arg: 0); |
| 29 | sleep(seconds: 1); // give it time to block in pause |
| 30 | pthread_kill(threadid: th, SIGUSR1); |
| 31 | sleep(seconds: 10); // signal handler must exit the process while we are here |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | // CHECK: DONE |
| 36 | |