For the solution to the critical section problem one synchronization tool is used which is known as semaphores. A semaphore ‘S’ is an integer variable which is accessed through two standard operations such as wait and signal. These operations were originally termed ‘P’ (for wait means to test) and ‘V’ (for single means to increment). The classical definition of wait is
While (S <= 0)
The classical definition of the signal is
In case of wait the test condition is executed with interruption and the decrement is executed without interruption.
A binary semaphore is a semaphore with an integer value which can range between 0 and 1.
Let ‘S’ be a counting semaphore. To implement the binary semaphore we need following the structure of data.
Binary Semaphores S1 , S2 ;
Initially S1 = 1, S2 = 0 and the value of C is set to the initial value of the counting semaphore ‘S’.
Then the wait operation of the binary semaphore can be implemented as follows.
if (C < 0)
The signal operation of the binary semaphore can be implemented as follows:
Wait (S1 );
if (C <=0)
Signal (S2 );