timeout on semaphore

timeout on semaphore

Post by Jens » Wed, 11 Aug 1999 04:00:00



Hi!

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:

alarm(5);
sema.wait();
alarm(0);
....Do my stuff
sema.signal();

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?

 
 
 

timeout on semaphore

Post by Christopher Bar » Wed, 11 Aug 1999 04:00:00


: Hi!

: 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:

: alarm(5);
: sema.wait();
: alarm(0);
: ....Do my stuff
: sema.signal();

        Any reason you're using a semaphore here?  Could you use pause() instead?  Timing out a semaphore doesn't make sense (you can set the semaphore to a no wait state if that's what you need)

--
    Christopher Bark
    4th Year Comp Sci
    Carleton University


 
 
 

timeout on semaphore

Post by John Simpso » Wed, 11 Aug 1999 04:00:00



> Hi!

> 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:

> alarm(5);
> sema.wait();
> alarm(0);
> ....Do my stuff
> sema.signal();

> 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;
alarm(5)
while (alarm_set == FALSE)
{
    sema.wait();

Quote:}

...Do stuff
sema.signal();

In the signal handler, set alarm_set to TRUE.

HTH
--
John H. Simpson Phone: 503-450-2667  FAX: 503-450-3629
CNF AdTech Center. (CNF Transportation, Inc.)
1717 NW 21st St.
Portland, OREGON 97209 USA
for e-mail, remove _not_oj_ from address

 
 
 

timeout on semaphore

Post by Cae » Wed, 11 Aug 1999 04:00:00


On Tue, 10 Aug 1999 10:16:07 -0700, John Simpson vouchsafed:


>> Hi!

>> 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:

>> alarm(5);
>> sema.wait();
>> alarm(0);
>> ....Do my stuff
>> sema.signal();

>> 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;
>alarm(5)
>while (alarm_set == FALSE)
>{
>    sema.wait();
>}
>...Do stuff
>sema.signal();

>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)

 
 
 

1. semaphore timeout

Hello,

Is there a way to specify a time out in msecs, that a semop operation will
last? I.e. I want semop to try for x msecs to get a semaphore, and afterthat
if it wasn;t succesful to exit.

Thanks,
MrZammler

2. LILO install on Redhat 2.1

3. Timeout on semaphores (in kernel context)

4. What is POSIX mean?

5. 2.5.49 - semaphore operations with timeouts

6. su and RBAC

7. timeout a semaphore

8. how can I change default boot partion from linux to dos?

9. : Semaphore with Timeout?

10. timeout requirement for semaphores

11. timeout a semaphore

12. timeout semaphore

13. Need a Posix semaphore timeout system