linux-sysprog · beginner · ~15 min
Decide when synchronisation is actually required.
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).
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.