r305_dm/TP4/Exo3/section_critique.c

44 lines
642 B
C
Raw Normal View History

2023-10-12 09:39:37 +02:00
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdint.h>
#include <assert.h>
#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);
}
}