/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* The following program displays a message, blocks the SIGINT
   signal while doing some useless work, unblocks the signal, and 
   does more useless work. The program repeats this sequence 
   continually in a loop.  This example is compiled using the following 
   instructions:  sigaddset.c < sigaddset.in.  The contents of sigaddset.in 
   are : 2.*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <signal.h>

int main() {
    double y;
    sigset_t intmask;
    int i, repeat_factor, j, k;
   
    printf("Enter repeat factor: ");
    scanf("%d", &repeat_factor); 
    sigemptyset(&intmask);
    sigaddset(&intmask,SIGINT);
    for(j =0; j < repeat_factor; j++) {
        sigprocmask(SIG_BLOCK,&intmask, NULL);
        fprintf(stdout,"SIGINT signal blocked\n");
        for (i = 0;i<repeat_factor;i++)
            y=sin((double)i);
        fprintf(stdout,"Blocked calculation is finished\n");
        sigprocmask(SIG_UNBLOCK,&intmask, NULL);
        fprintf(stdout,"SIGINT signal unblocked\n");
        for(k = 0; k<repeat_factor; k++)
            y = sin((double)i);
        fprintf(stdout,"Unblocked calculation is finished\n");
    }
}
