3

If you consider a binary semaphore and mutex, which one is faster? I mean, takes less instructions. What additional data does mutex maintain compared to semaphore?

1 Answer 1

8

This is implementation dependent, but you will probably find that mutex has been implemented to be slightly faster. Mutexes are typically implemented with test and set, while semaphores are often implemented with test and increment or as a mutex guarding a variable that is incremented.

I would suggest using a mutex in most cases, but not due to speed; simply because code written using mutexes is easier to understand as the semantics are less complicated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.