semaphore timeout

semaphore timeout

Post by MrZammle » Thu, 11 Oct 2001 19:45:14



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

 
 
 

semaphore timeout

Post by Norman Blac » Fri, 12 Oct 2001 04:40:17


Not that I know of.

I would be happy to be mistaken.

--
Norman Black
Stony Brook Software
nospam => stonybrk


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


 
 
 

semaphore timeout

Post by Jim Patterso » Fri, 12 Oct 2001 10:11:36



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

Semaphores are supposed to fail with EINTR on any signal, including a
timer. So, you should be able to set a timer e.g. with setitimer, then
call semop. If the timer expires before the semaphore completes, the
semaphore operation should fail setting errno to EINTR. By testing the
error return you can determine the outcome and take appropriate action.

----
Jim Patterson
Ottawa, Ont
CANADA

 
 
 

semaphore timeout

Post by Norman Blac » Sat, 13 Oct 2001 04:36:23


I assume also that you would need a signal handler for the alarm signal to know
if the EINTR from semop came from the alarm or some other signal.

An interesting idea that should work on Linux. Probably not portable since
itimers are per process, not per thread. In Linux processes and threads are the
mostly identical.

--
Norman Black
Stony Brook Software
nospam => stonybrk



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

> Semaphores are supposed to fail with EINTR on any signal, including a
> timer. So, you should be able to set a timer e.g. with setitimer, then
> call semop. If the timer expires before the semaphore completes, the
> semaphore operation should fail setting errno to EINTR. By testing the
> error return you can determine the outcome and take appropriate action.

> ----
> Jim Patterson
> Ottawa, Ont
> CANADA

 
 
 

1. Need a Posix semaphore timeout system

Hi all,

I work under HP-UX and Solaris with POSIX semaphores. I need an
unexisting API like "sem_wait" with a timeout. In fact, the "sem_wait"
and "sem_trywait" APIs are not sufficient because I would like my
processes to be blocked until a certain amount of time is passed. And I
see no timeout management in the POSIX APIs.

Am I bound to use a timer by calling "create_timer" and to manage the
send of a signal to the blocked process in order to exit the "sem_wait"
? And if such a procedure is mandatory, is somenone can show me quickly
how to handle the signal (or the correct manual entry) ?

Thanx for all,

O. Rey

2. Linux Performance on a Sparc 2?

3. Timeout on semaphores (in kernel context)

4. MOSIX question

5. 2.5.49 - semaphore operations with timeouts

6. Problem UNBATCHER

7. timeout a semaphore

8. printer hangs sol 2.4

9. timeout on semaphore

10. : Semaphore with Timeout?

11. timeout requirement for semaphores

12. timeout a semaphore

13. timeout semaphore