๐ WAYPOINT LESSON
Checkpoint โ The Thread-Safe Job Queue
โญโญ intermediateโณ 25 min read๐ Lesson 119 of 265
Combine locking, atomic updates, and worker coordination into a queue that never loses or duplicates work.
The gate (mini-build)
A job queue drained by concurrent workers โ the producer/consumer core:
Enqueue(string job)โ adds a job.RunAll(int workers)โ startsworkersthreads; each worker repeatedly takes one job (if any) and processes it: callCjConcurrency.Pause()(the simulated work), then record"done:" + jobinto the results.- Every job is processed EXACTLY ONCE โ no losses, no duplicates โ even though workers take jobs one at a time from a shared queue.
Resultsexposes the recorded entries;RunAllreturns after all workers finish (join your threads).
The graded test runs 20 jobs across 4 workers with 5 ms simulated work and asserts exact counts and no duplicates.