#include #include #include #include #include #include #include "helpers.h" #include "helpers.c" int x = 2, y = 3; sigset_t quitset; int swap(int *x, int *y) { sigemptyset(&quitset); sigaddset(&quitset, SIGQUIT); sigprocmask(SIG_BLOCK, &quitset, NULL); int tmp = *x; *x = *y; *y = tmp; sigprocmask(SIG_UNBLOCK, &quitset, NULL); } void sig_handler(int signo) { switch (signo) { case SIGQUIT: printf("x=%d y=%d\n", x, y); break; } } int main(int argc, char *argv[]) { assert(set_signal_handler(SIGQUIT, sig_handler) == 0); while (1) { swap(&x, &y); } }