linux-sysprog · beginner · ~15 min

Critical section nesting

Track lock state at a point in time.

Challenge

Implement int in_critical_section(const char *ops, int k) returning 1 if the mutex is held immediately after processing the first k ops ('l'=lock, 'u'=unlock), else 0.

Starter code

int in_critical_section(const char *ops, int k) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.