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.
Recommended Posts:
- Mutex vs Semaphore
- Mutex lock for Linux Thread Synchronization
- Classical problems of Synchronization with Semaphore Solution
- Monitor vs Semaphore
- Difference between Binary Tree and Binary Search Tree
- Difference between General tree and Binary tree
- Difference between Binary tree and B-tree
- Difference between Binary Heap, Binomial Heap and Fibonacci Heap
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Relationship between number of nodes and height of binary tree
- Difference between Stop and Wait, GoBackN and Selective Repeat
- Difference between Stop and Wait protocol and Sliding Window protocol
- Similarities and Difference between Java and C++
- Difference between Yaacomo and and XAP
- Difference between VoIP and and POTS
- Difference and Similarities between PHP and C
- Difference between Time Tracking and Time and Attendance Software
- Difference Between Single and Double Quotes in Shell Script and Linux
- Difference between ++*p, *p++ and *++p
- Difference Between DOS and Windows
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.

