timeout a semaphore

timeout a semaphore

Post by Arie Tuchfel » Wed, 15 Sep 1999 04:00:00



How can I timeout a non signaled semaphore? i.e.:
        static struct sembuf op_decr[] = {
            0, -1, 0 // decrement sem#0 by 1
        };
        semop(m_semid, &op_decr[0], 1); // blocks untill semval > 0.

Usually I use select() with timeout, but select() uses file descriptor,
is there a file descriptor for a semaphore ???

 
 
 

timeout a semaphore

Post by Andrew Gabri » Wed, 15 Sep 1999 04:00:00




Quote:>How can I timeout a non signaled semaphore? i.e.:
>        static struct sembuf op_decr[] = {
>            0, -1, 0 // decrement sem#0 by 1
>        };
>        semop(m_semid, &op_decr[0], 1); // blocks untill semval > 0.

>Usually I use select() with timeout, but select() uses file descriptor,
>is there a file descriptor for a semaphore ???

You can use alarm() (or similar timer functions) to break you
out of the semop(). However, I have found this to be unreliable
on SCO openserver and HP-UX, where the kernel semaphore can get
into an invalid state when semaphore calls are broken by signals
(this shouldn't happen, it's a bug).

If the platform you are using supports POSIX semaphores (sem_post,
sem_wait, etc), you might find these worth investigating instead.

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

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. Apache 1.3a1: Proxy setup?

3. Timeout on semaphores (in kernel context)

4. Aiee: scheduling in interrupt

5. 2.5.49 - semaphore operations with timeouts

6. POP3 server needed

7. timeout on semaphore

8. SCSI testing program?

9. : Semaphore with Timeout?

10. timeout requirement for semaphores

11. timeout a semaphore

12. timeout semaphore

13. Need a Posix semaphore timeout system