On Tue, 10 Aug 1999 10:16:07 -0700, John Simpson vouchsafed:
>> Is there a way to to set a timeout on a semaphore?
>> I tried to use an alarm signal but it dosent seem to work properly.
>> This is what i did:
>> ....Do my stuff
>> The program waits at sema.wait():
>> When the alarm arrives the program(after five seconds) jumps to the
>> alarmhandler wich i have defined.
>> The it jumps back to sema.wait(). But I want to skip sema.wait() after the
>> alarm signal.
>> Is there a way to do this using signals or is there any other way?
>Have you tried putting your sema.wait() call in a while loop that is
>controlled by the signal handler:
>alarm_set = FALSE;
>while (alarm_set == FALSE)
>In the signal handler, set alarm_set to TRUE.
if you do use this solution, be sure to declare the variable alarm_set
as volatile, otherwise an optimising compiler might optimise the loop
down to "while (1)..."
Carl Jacobs - Software Engineer by title, SysAdmin by fait accompli,
ASR's Chief Bastard of Odd Religious Lore by acclamation.
Opinions expressed are not those of Raytheon Systems Company.
cjacobs at fallschurch.esys.com, darian at rtfm.netset.com (munged)