Messages in this thread | | | From | Gordon Oliver <> | Subject | Re: Question on handling SIGALRM. | Date | Thu, 8 May 1997 02:51:57 -0400 (CST) |
| |
...Richard B. Johnson says...: > void handler(int sig) > { > global_variable= TRUE; > } > > signal(SIGALRM, handler); > global_variable = FALSE; > alarm(timeout); > if(global_variable == FALSE) > status = read(fd, buffer, len); > else > ......
ahm... don't do this. you only shorten the race. If you must do this, Alan Cox sent a much better (and correct solution) to this list that went something like
void handler(int sig) { siglongjump(stuff); }
... signal(SIGALRM, handler); if (setlongjump(stuff)) return TIMEOUT; alarm(timeout); status=read(fd, buffer, len); alarm(0); ................ There is still a race, but now it is between the return from the read and the alarm(0), which may cause a false error. You might be able to avoid it, but I don't know how.
... btw, the code fragment above is from memory, and almost certainly misuses functions, but the idea should be right. (use the man pages)
This should be in a faq somewhere... -gordo
| |