BINARY SEMAPHORE




Has 0 and 1 value. The wait operation only works when the semaphore is 1 and the signal operation succeeds when semaphore is 0

Analysis of Binary Semaphore approach:


1. A binary semaphore has two components-
a. An integer value which can be either 0 or 1.
b. An associated waiting list (usually a queue).

2. The waiting list of binary semaphore contains the processes that got blocked when trying to enter the critical section.

3. In waiting list, the blocked processes are put to sleep.

4. The waiting list is usually implemented using a queue data structure.

5. Using a queue as waiting list ensures bounded waiting.

6. This is because the process which arrives first in the waiting queue gets the chance to enter the critical section first.

7. The wait operation is executed when a process tries to enter the critical section.

8. The signal operation is executed when a process takes exit from the critical section.

9. Binary semaphores are mainly used for two purposes-
a. To ensure mutual exclusion.
b. To implement order in which the process must execute.

Demo

Steps

Lights

Input

Enter the integer value that is the number of process required and that will be added to the initial state.

Than for process the process click on the repective process and than it will go to the appropriate state which is availabe according to algorithm.

Output

According to the user input on clicking the process the output will be shown by placing the process button on appropriate places according to the algorithm of binary semaphore.

Also the semaphore value is shown above the added state according to the configuration on that instant

Lights