1 // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 #include <assert.h> 3 #include <stdlib.h> 4 #include <signal.h> 5 #include <unistd.h> 6 #include <stdio.h> 7 8 static bool signal_handler_ran = false; 9 10 void do_nothing_signal_handler(int signum) { 11 write(1, "HANDLER\n", 8); 12 signal_handler_ran = true; 13 } 14 15 int main() { 16 const int kSignalToTest = SIGSYS; 17 assert(SIG_ERR != signal(kSignalToTest, do_nothing_signal_handler)); 18 sigset_t empty_set; 19 assert(0 == sigemptyset(&empty_set)); 20 sigset_t one_signal = empty_set; 21 assert(0 == sigaddset(&one_signal, kSignalToTest)); 22 sigset_t old_set; 23 assert(0 == sigprocmask(SIG_BLOCK, &one_signal, &old_set)); 24 raise(kSignalToTest); 25 assert(!signal_handler_ran); 26 sigset_t all_but_one; 27 assert(0 == sigfillset(&all_but_one)); 28 assert(0 == sigdelset(&all_but_one, kSignalToTest)); 29 sigsuspend(&all_but_one); 30 assert(signal_handler_ran); 31 32 // Restore the original set. 33 assert(0 == sigprocmask(SIG_SETMASK, &old_set, NULL)); 34 printf("DONE"); 35 } 36 37 // CHECK: HANDLER 38 // CHECK: DONE 39