linux-sysprog · intermediate · ~15 min
Recognise the symptom of an unsynchronised increment race.
Two threads each increment a shared counter. Implement int lost_update(int initial, int incs_a, int incs_b, int observed) returning 1 if observed is less than the correct total (initial + incs_a + incs_b), indicating a lost update, else 0.
int lost_update(int initial, int incs_a, int incs_b, int observed) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.