Binary Semaphore
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; int C; 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. Wait (S1) C--; if (C < 0) { Signal (S1); Wait (S2); } Signal (S1);
The signal operation of the binary semaphore can be implemented as follows:
Wait (S1); C++; if (C <=0) Signal (S2); Else Signal (S1);