Semaphores

Describe how a Semaphore is used in Operating System?

Questions by tereraiterence

Showing Answers 1 - 8 of 8 Answers

ankscorek

  • Mar 8th, 2009
 

Semaphores provide mutual exclusion. They are used for process sync and are used to resolve deadlock conditions.
They are used in pairs basically wait() and signal().
Commonly used semaphore is mutex()

Semaphore is a "process synchronization tool" which are assigned by two operation
a. wait (p)
b. signal (v)

It states that if there are many proceess sharing a same variable, then other process must wait it until the process in critical section is completed, as the process in critical section is completed its send a signal to the other process to enter a critical section.

  Was this answer useful?  Yes

Semaphore provides a synchronous access to a shared resource. If multiple threads can access a hared resource concurrently, we need a mechanism that can prevent other threads to access the resource while one of the thread is using the resource.
 
Any thread that needs an access to the resource must acquire the semaphore. If the semaphore is busy, it will be blocked/sleep. When the thread that is using the resource is done, it issues wakeup to the blocked threads.

  Was this answer useful?  Yes

semaphore is a abstract datatype and monitor is a  programming construct...

although both performs the function of mutual inclusion using monitor is sometimes safer than using semaphores because  in monitor functions related to the resources are placed in a single place and in semaphore the functions are distributed and less structured...there is a fear of order of calling the functions i.e wait and signal of semaphore..if the order goes wrong the deadlock condition may arise but in case of monitor it is more safe because the related function are structured in a single block..

  Was this answer useful?  Yes

somdev

  • Jul 21st, 2012
 

A semaphore is a synchronization tool that provides a general-purpose solution for controlling access to critical sections.
A semaphore is an abstract data type (ADT) that defines a nonnegative integer variable which, apart from initialization, is accessed only through two standard operations: wait and signal.

  Was this answer useful?  Yes

user569

  • Feb 7th, 2013
 

Semaphore is a shared binary variable which can take values either 0 or 1. The primary purpose of them is to ensure mutual exclusion property between or among the two or more processes that want to enter into access the shared code, formally called as "Critical Section". Its necessary because if two processes are allowed to execute the same section of code simultaneously, then if they update same variable in the code at same time, conflicts will occur in the result of that process. So one process must be allowed to enter into the critical section. The two operations that can be performed on semaphore variables are: P(S) and V(s). P(s) checks if the value of semaphore variable S is less than 0, if so, then makes the process to wait in the loop. V(S) process increments the value of Semaphore. Whenever the process completes the execution of the critical section, it sets the value of semaphore to 1. The waiting process finds the value now 1, now its allowed to enter the critical section and execute its code.

Semaphore is an non-negative integer, which is used to provide mutual exclusion to processes trying to access a same resource.
For example, if you are copying a file, then you cannot move it to some other folder. This is achieved by the copying process, which acquires a lock on that file. This does not allow any other process to access that file/resource.
Semaphores are used to prevent deadlock conditions, where 2 or more process keep on waiting for some event to happen, but that event may never happen.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions