The following program produces the output:

Begin
Done
Begin
...and then hangs.

Can anyone help me understand why?

Thankyou,
Max.



#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <unistd.h>

jmp_buf timer;

void alarm_handler(int dummy)
{
 longjmp(timer, 1);
}

void speedtest(void)
{
 fprintf(stderr, "Begin\n");
 signal(SIGALRM, alarm_handler);

 if (setjmp(timer) == 0) {
   alarm(1);
   while(1) {};
 }

 signal(SIGALRM, SIG_DFL);
 fprintf(stderr, "Done\n");
 return;
}

int main(int argc, char* argv[])
{
 speedtest();
 speedtest();

 return 0;
}


-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/



Reply via email to