LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-22-2008, 08:31 AM   #1
Manjunath1847
Member
 
Registered: Mar 2007
Posts: 44

Rep: Reputation: 16
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
 
Old 04-22-2008, 11:45 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 492

Rep: Reputation: 50
"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.
 
  


Reply

Tags
programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux semaphore behaviod icarus127 Linux - General 0 10-07-2007 02:01 PM
Linux kernel module programming(Signal and semaphore) eshwar_ind Programming 1 02-16-2004 12:10 PM
how to use fork and semaphore in C/C++ in Linux? cs87668 Programming 1 06-20-2003 10:07 AM
semaphore init problem in linux marry_jeo Programming 0 02-25-2003 11:20 PM


All times are GMT -5. The time now is 08:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration