Terminology
|
Term |
Description |
|---|---|
|
Mutex (Mutual Exclusion) |
|
|
Semaphore |
|
|
Spinlock |
|
|
Condition Variable |
for many applications, mutual exclusion is not enough. Threads attempting an operation may need to wait until some condition P holds true. A busy waiting loop
will not work, as mutual exclusion will prevent any other thread from entering the monitor to make the condition true |
(Mutex) vs (Mutex Semaphore) vs (Binary Semaphore)
In a Mutex, only the thread which have locked it can unlock it. If any other thread comes to lock it, it will wait
- In a Binary Semaphore, it is OK for B to take the semaphore and A to give it. Again, a binary semaphore is NOT protecting a resource from access. The act of Giving and Taking a semaphore are fundamentally decoupled
- In a Mutex Semaphore is same as Mutex. It is a binary semaphore with the restriction that
|
Mutex |
Mutex Semaphore |
Counting Semaphore | |
|---|---|---|---|
|
Lock |
Lock |
(P) Claim/Decrease | |
|
Unlock |
Unlock |
(V) Release/Increase |
NOTE: in case you’ve ever wondered at the bizarre letters used for claiming and releasing semaphores, it’s because the inventor was Dutch. Probeer te verlagen:
- probeer - means to try and decrease
- verhogen - means to increase
Articlees
- What is a Semaphore - https://stackoverflow.com/questions/34519/what-is-a-semaphore/40238#40238
- Mutex vs Semaphores - https://barrgroup.com/Embedded-Systems/How-To/RTOS-Mutex-Semaphore