What is the difference between a mutex and a semaphore?

What is the difference between a mutex and a semaphore?

Approach: Compare ownership and signaling.

A mutex is a locking mechanism intended for mutual exclusion, where only the thread that locked it can unlock it. A semaphore is a signaling mechanism that uses a counter to manage access to multiple instances of a resource.

Follow-up: Can a semaphore be used as a mutex?

Key concepts: binary semaphore, counting semaphore, ownership.