User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Computer Science and Software Design section within the Software Development category of DaniWeb, a massive community of 391,590 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,653 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Computer Science and Software Design advertiser:
Views: 1826 | Replies: 1
Reply
Join Date: May 2005
Posts: 18
Reputation: Mr. is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Mr. Mr. is offline Offline
Newbie Poster

Semaphores and resources

  #1  
Jun 28th, 2005
Hello,

if we need to protect a given number of resources, do we need 1 semaphore for each?

Let's say:

4 shared memory areas, used by 3 processes;

Will we need to create a semaphore set with 3 semaphores?

Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Posts: 56
Reputation: Sauce is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Sauce Sauce is offline Offline
Junior Poster in Training

Re: Semaphores and resources

  #2  
Jul 24th, 2005
You shouldn't. The concept of a semaphore is simple, you set the value to a number (in your case 4) when you use one of the resources you dec(-1) from the value and so on. Then if the value is <=0 then all sources are used so it waits for the value to be incremented again. You have to make sure that the single semaphore is used in all the processes. Basically pass it by reference to the threads.

At least thats how its implemented in linux, not sure about windows.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Computer Science and Software Design Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Computer Science and Software Design Forum

All times are GMT -4. The time now is 11:19 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC