SEMAPHORES:

What is Semaphore ?

It is a very popular tool used for process synchronization. Semaphore is used to protect any resources such as Global shared memory that needs to be accessed and updated by many processes simultaneously.

Semaphore acts as a guard / lock on the resources:

Whenever a process needs to access the resource, it first needs to take permission from the semaphore. Semaphore give permission to access a resource if resource is free otherwise process has to wait.

The semaphore is implemented by variable like:

Counter, a waiting list of processes and two methods( eg. Functions) signal and wait with integer values.

Semaphore

The semaphore is accessed by only two indivisible operations known as 'wait' ad 'signal' operationa which is denoted by p and v.

Example

- process performs 'wait' operation when tries to enter 'critical section'.

- semaphore allow process to enter critical section is not being used by any process otherwise deny it.

- the Count of the semaphore is decremented if a process access critical section.

-Initially the count of semaphore is 1. And if it is accessed then count decremented and become zero(0).

- when a process exits the CS, if perform the signal operations which is an exit criterion.

In this way, the solution to CS using semaphore satisfied that designed protocols.

The semaphore whose value either 0 or 1 is known as binary semaphore. This concept is basically used in mutual exclusion.

do 
{ 
wait (semaphore) 
{ 
critical section 
} 
Signal (semaphore) 
{ 
---- 
---- 
} 

When there is more processes 3 which want to access more available resources say 3-4 memories unit then the semaphore is taken to guard all the three memory location with value 3. It means that 3 processes at the same time can access the semaphore. After giving the access to third process the value of account become 0.

This type of semaphore that takes a value greater than one is known as 'counting semaphore'.

21- Interprocess Communication- Semaphores- Operating System








    CLICK HERE TO Download This PDF NOTES




Facebook Likes

Youtube