LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   semaphore in linux with maxcount and time out (http://www.linuxquestions.org/questions/linux-newbie-8/semaphore-in-linux-with-maxcount-and-time-out-637024/)

Manjunath1847 04-22-2008 08:31 AM

semaphore in linux with maxcount and time out
 
I am porting a Windows application to Linux. I need to set a time out for the semaphore wait operation. I did it with sem_trywait in a loop. Is there a better way?

How to set set the maximum count for a semaphore ? Anybody has a wrapper written with these functionalities implemented ?

thanks
Manju

jf.argentino 04-22-2008 11:45 AM

"man sem_wait" gives sem_timedwait which seems to do the job.
It's easy to get the current semaphore value with "sem_getvalue" and then don't "sem_post" if the value is greater than the max you need.


All times are GMT -5. The time now is 03:32 AM.