FOR FREE CONTENT

Type of Semaphore variable 

 

They are two types

1.  Counting semaphore. (-α to + α)

2.  Binary semaphore (Mutex). (0 or 1)

 

# Binary semaphore means when mutual exclusion supported, i.e. no two processes can access a critical section at a time.

 

# But counting semaphore where more than one process can enter a critical section at a time.

 

Semaphore variables using two operations: Down and Up or P and V or Wait and Signal.

 

Counting Semaphore

 

 

Counting semaphore allowed more than one process at Critical Section

 

Some important point for Counting Semaphore operation: 

1. More than one process is allowed at the critical section but it defines a number as a limit that how many maximum numbers of processes can enter into the critical section.

In the above code, the value is an integer variable that stores the capacity of the critical section.

 

2. Semaphore may be initialized to a non-negative integer value.

 

3. The Wait() operation is executed when a process tries to enter into the critical section. The wait() operation decrement semaphore value before entering the process into the critical section i.e. decreases the total capacity and check for vacancy every time when the process enters into the critical section.

 

If the value is negative (capacity of the critical section is full), then the process goes to sleep and adds the process to waiting or suspended queue list for future execution

 

4. The Signal() operation is executed when the process tries to leave from the critical section. The signal() operation increments semaphore value i.e. increases the capacity of the critical section every time when the process leaves the critical section and creates a vacancy.

 

After incrementing the value, if the resulting value is less than or equal to zero (if any vacancy creates at the critical section) then wake the process up from the suspended queue list.

 

# Other than these operations, there is no way to scrutinize or operate semaphores.

 

Process never gets blocked while performing "Up" operation and it gets blocked while performing "Down" operation.