In: Computer Science
One simple method to protect a critical section is to use mutex locks, also called spinlocks. An alternative method would be use a binary semaphore initialized to 1, with the implementation that uses busy waiting. Is there any real difference between these two methods? Explain.
Dear Student,
Answer :
BINARY SEMAPHORE MUTEX
It's functionality is based up on signalling mechanism | It's functionality is 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 goes out from critical section. |
Semaphore value is varied according to wait () and signal () operations. | Mutex values can be changed just as locked or unlocked. |
Multiple number of threads can acquire binary semaphore at a time concurrently. | Only one thread can have mutex at a time |
Binary semaphore does not have 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. |
Hope This Helps.
All The Best