linux-sysprog · intermediate · ~15 min
Validate correct mutex usage.
A trace uses 'l' (lock) and 'u' (unlock) on one non-recursive mutex. Implement int locks_balanced(const char *ops) returning 1 only if it never unlocks an unlocked mutex, never locks an already-held one, and ends unlocked.
int locks_balanced(const char *ops) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.