RTOS & Real-Time Concepts · Interview question

Why shouldn't you use a mutex (instead of a semaphore) to signal an event from an ISR?

A strong answer

Because a mutex's semantics are fundamentally about ownership and don't fit signaling from an interrupt. A mutex must be given back by the same task that took it (ownership), but signaling means one party (the ISR) gives and a different party (the task) takes, there's no consistent owner, which violates the model. More concretely, an ISR can't take a mutex because taking can block and ISRs must never block, and a mutex's key benefit, priority inheritance, only makes sense when a task holds a resource other tasks need, there's no holder in an event-signaling scenario, so inheritance is irrelevant. RTOSes generally don't even provide a give-mutex-from-ISR call. The correct tool is a binary or counting semaphore, which is ownerless by design and has a FromISR give. Using a mutex where you mean "signal" is a category error: you want event notification (semaphore), not resource protection (mutex). Conversely, using a plain semaphore where you mean "protect a shared resource" loses priority inheritance and can cause unbounded priority inversion, so matching the primitive to the intent matters in both directions.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Mutexes & Semaphores

Coordinating concurrent tasks: a mutex for mutual exclusion (ownership + priority inheritance) vs a semaphore for signaling and counting, and why you give a semaphore from an ISR, not take a mutex.

More Mutexes & Semaphores questions

Browse all 472 interview questions
Why shouldn't you use a mutex (instead of a semaphore) to signal an event from an ISR? | EmbeddedPrep.io