A: Rules of thumb:
- By semaphore we actually mean counting semaphore. By mutex we actually mean mutex semaphore. A mutex is essentially a binary semaphore. You can replace any Mutex with a Semaphore of MaxCount 1.
- Mutexes are usually more efficient than binary semaphores.
- Mutex has an owner concept: unlocking a mutex can be only done by the thread that locked (or, equivalently, "owns") the mutex.
- However, though I don't think it's a real issue in this particular case either, mutex can do fancy things with the thread that has locked the mutex (mutex owner thread), like raising its priority to the highest one of the threads waiting for the mutex to prevent so called priority inversion. (huican ping notion, not in the original version)
Sunday, April 16, 2006
Semaphore and Mutex
What's the difference between semaphore and mutex?