Skip to main content
๐Ÿ“œ 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:

  1. Enqueue(string job) โ†’ adds a job.
  2. RunAll(int workers) โ†’ starts workers threads; each worker repeatedly takes one job (if any) and processes it: call CjConcurrency.Pause() (the simulated work), then record "done:" + job into the results.
  3. Every job is processed EXACTLY ONCE โ€” no losses, no duplicates โ€” even though workers take jobs one at a time from a shared queue.
  4. Results exposes the recorded entries; RunAll returns 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.