This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with alarm() not functioning twice in one program.


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]