linux-sysprog · beginner · ~15 min

Does this need synchronisation?

Decide when synchronisation is actually required.

Challenge

Implement int needs_sync(int shared, int written_by_multiple) returning 1 only if the data is shared AND written by more than one thread (read-only or thread-local data needs no lock).

Starter code

int needs_sync(int shared, int written_by_multiple) {
    /* TODO */
    return 0;
}

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