what is semaphore?

haneefnb
haneefnb used Ask the Experts™
on
Hi , plz tell me what is semaphore?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
Top Expert 2009
Commented:
The basic concept, a semaphore is 2 things:
  1) A resource count, ie. how much of a given resource there is
  2) A condition variable, ie. a way to signal that something has changed

Semaphores are implemented using 2 atomic operations, P and V. P is used to acquire, V is used to relinquish.

At its simplest, a semaphore is a hall monitor that lets one person go to the restroom at a time. You have to have the hall "pass" (P). If there is only one hall pass, then the next person cannot go until the first person returns the pass (V). If you want to allow max 2 people in the restroom, then you need 2 hall passes (initial semaphore value of 2) so initially two workers can call P successfully but the third would block until one of the workers called V.

On UNIX/Linux you can use the semctl/semop system calls to implement P and V, see the man pages on those, or just ask more questions. The Java API is obviously different.

Hi, you might read previous posts with other students.

http://www.experts-exchange.com/OS/Development/Q_24258048.html?sfQueryTermInfo=1+10+mrjoltcola+semaphore

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial