linux-sysprog · intermediate · ~15 min
Verify the global lock-ordering rule.
Implement int same_lock_order(const int *a, const int *b, int n) returning 1 if both threads acquire the n locks in the identical order (which prevents deadlock), else 0.
int same_lock_order(const int *a, const int *b, int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.