Difference between Binary Semaphore and Mutex

Prerequisite – Process Synchronization

1. Binary Semaphore :
Binary semaphores are semaphores which can assume the values 0 and 1 only. They are used for implementing the locks by using signalling mechanism for achieving mutual exclusion.

Here, if the value of semaphore is 0 it means it is locked so, lock is unavailable.
If the value of semaphore is 1 it means it is unlocked so, lock is available.

2. Mutex :
Mutex is the short form of Mutual Exclusion.only one thread can enter into critical section at a time. A mutex is a binary variable which provides locking mechanism.

Difference between binary semaphore and mutex :

Binary Semaphore Mutex
Its functions based up on signalling mechanism Its functions based up on locking mechanism
The thread which is having higher priority than current thread can also release binary semaphore and take lock. The thread which has acquired mutex can only release Mutex when it exits from critical section.
Semaphore value is changed according to wait () and signal () operations. Mutex values can be modified just as locked or unlocked.
Multiple number of threads can acquire binary semaphore at a time concurrently. Only one thread can acquire mutex at a time
Binary semaphore have no ownership. There is ownership associated with mutex because only owner can release the lock.
They are faster than mutex because any other thread/process can unlock binary semaphore. They are slower than binary semaphores because only thread which has acquired must release the lock.
If you have number of instances for resource it is better to use Binary semaphore. If you have single instance for resource it is better to use mutex.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.