All jobs / Embedded / hardware / RTOS
Embedded / hardware interview question · 0–1 years
When do you reach for a mutex, and when for a binary semaphore?
The strongest answer
A mutex protects shared data — it has an owner who must give it back, and it can lend priority to whoever is blocked; a binary semaphore signals an event from an ISR or a task to a task
Why it works
Exactly — ownership and priority inheritance are what make a mutex the right tool for shared data.
What a good answer covers
- Mutex guards data; semaphore signals events.
- A mutex has an owner; give it back.
- Only a mutex can inherit priority.
- Signal from an ISR with a semaphore.
Answers that fall short
- Close, but not the strongest: A mutex is for protecting a resource and a semaphore is for signalling — beyond that they behave much the same
Right split; the difference that bites is ownership and priority inheritance, which a semaphore has neither of. - Weak: They are the same object; mutex is just the name the RTOS uses for a binary semaphore
They are distinct: a semaphore has no owner, so it cannot inherit priority or catch misuse. - Red flag: I use whichever one is already in the file, and if it deadlocks I take the lock out
Deleting the lock trades a hang you can see for data corruption you cannot.
Who gets asked this
More RTOS questions
- When do you pick an RTOS over a main-loop, and when not?
- A UART interrupt needs to hand a byte to a task through an RTOS queue. What must the ISR do differently?
- Average loop time is fine; the plant oscillates. What did you miss?
- A task should sample every 10 ms. It sleeps for 10 ms at the end of each pass, and over minutes the period…
- Two tasks write a global “state” byte. What is the grown-up move?
- A low-priority task holds a lock a high-priority task needs. What do you name?
- One task corrupts another’s stack. What do you add besides “be careful”?
- You have a 2 ms control deadline. What number do you present?