Hi,
I am trying to learn Critical Sections. I have written a small
program. Source code problem below.
What the program is doing is disabling the CRTL-C signal in the
critical section. My problem is that when in the Critical Section I
press the CTRL-C signal more than once. As supposed nothing happens,
but when critical section ends, should it give me all the CTRL-C
signals pressed or just one (its giving me one)?
How should the exact implementation be?
I hope some one out there understands my problem.
Thanks in advance
/* Source Code */
#include <stdio.h>
#include <errno.h>
#include <signal.h>
int cnt;
void CTRL_C_Handler (int sig)
{
cnt++;
printf ("%d. Now we are in CTRL_C_Handler.\n", cnt);
(void) signal (SIGINT, CTRL_C_Handler);
} // end method CRTL_C_Handler
main()
{
system ("clear");
(void) signal (SIGINT, CTRL_C_Handler);
sigset_t masking;
cnt=0;
sigemptyset (&masking);
sigaddset (&masking, SIGINT);
if (sigprocmask (SIG_BLOCK, &masking, NULL) == -1)
printf ("An error encountered: %s.\n", strerror(errno));
printf ("Enterend in Critical Section. Last for 5 seconds.\n");
printf ("Pressing CTRL-C will be useless.\n");
sleep(5);
printf ("Critical Section is ending now.\n");
if (sigprocmask (SIG_UNBLOCK, &masking, NULL) == -1)
printf ("An error encountered: %s.\n", strerror(errno));
while(1); // infinite loop
} // end main