Practice ยท 1 of 1
Lost Updates & Their Cure
The boilerplate declares a tiny work harness:
``c
/* runs workers threads, each calling inc_n_times(count_target)
per_thread times; joins them all; returns 0 if all joined ok.
inc_n_times is YOURS to implement. */
int run_workers(int workers, int per_thread);
/* the shared counter all workers increment */
extern long g_counter;
/* the mutex protecting it โ you must USE it in inc_n_times */
extern mtx_t g_counter_mtx;
void inc_n_times(int n); /* increments g_counter exactly n times */
``
Round 1 of the test runs your implementation with the mutex and expects
the exact total. Round 2 (after you pass) reveals what happens without
it โ the harness runs the *reference buggy* counter to demonstrate the
lost update.
Difficulty: intermediate
Back to lesson: Practice: Race & Mutex Gym