Coupon Accepted Successfully!



Semaphores are used for synchronization mechanisms. A semaphore is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait and signal.
Definition of wait and signal operation. Let S be a semaphore.

wait(S) {
While (S <= 0); // no-operation
S-- ;


signal(S) {

Using semaphores, implementing mutual exclusion becomes very easier.

do {
wait (mutex)
Critical section
signal (mutex)
Remainder section

} while (1);

In this solution, if a process is in critical section, then any other process trying to get into CS must loop continuously in the entry code. This continuous looping is called Busy Waiting and it wastes CPU cycles. This type of semaphore is called Spinlock because the process spins while waiting for the lock.
Spinlocks are useful in multiprocessor systems where context switch is highly expensive and if locks are to be held for smaller time than spinning is beneficial.

Binary Semaphores

A binary semaphore is a semaphore with an integer value that can range only between 0 and 1. A binary semaphore can be simpler to implement rather than a counting semaphore, depending on the underlying hardware.

Test Your Skills Now!
Take a Quiz now
Reviewer Name