linux-sysprog · intermediate · ~15 min

Consistent lock order

Verify the global lock-ordering rule.

Challenge

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.

Starter code

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.