D. The mutex is never released, causing a deadlock
Solution
Step 1: Check mutex take and give usage
The code takes the mutex but never calls xSemaphoreGive() to release it.
Step 2: Understand consequences of not releasing mutex
Not releasing the mutex causes other tasks to wait forever, leading to deadlock.
Final Answer:
The mutex is never released, causing a deadlock -> Option D
Quick Check:
Missing give = deadlock risk [OK]
Hint: Always give mutex after take [OK]
Common Mistakes:
Forgetting to release mutex
Assuming increment fails without mutex
Confusing order of take/give
5. You have two tasks that both update a shared sensor reading variable. How should you use a mutex to ensure safe updates and avoid blocking tasks too long?
hard
A. Take the mutex once at system start and never release it
B. Take the mutex, update the variable quickly, then give the mutex immediately
C. Update the variable without mutex and rely on task priorities
D. Use two separate mutexes for the same variable
Solution
Step 1: Understand mutex best practice for shared data
Mutex should be held only briefly to protect the critical section (variable update).
Step 2: Evaluate options for safe and efficient updates
Taking and giving mutex immediately around update prevents blocking other tasks too long.
Final Answer:
Take the mutex, update the variable quickly, then give the mutex immediately -> Option B
Quick Check:
Short mutex hold = safe and efficient [OK]
Hint: Lock only during update, then unlock fast [OK]
Common Mistakes:
Holding mutex too long blocking tasks
Never releasing mutex causing deadlock
Ignoring mutex and risking data errors
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.