Master the fundamental concepts of threads & concurrency through this focused micro-challenge.
Thread pools keep a fixed set of worker threads alive, pulling tasks from a shared queue. Spawning a thread per request wastes milliseconds on stack setup and scheduler registration; pools trade memory for steady latency under bursty load.
Components:
For example, a pool of 4 workers draining 100 tiny jobs finishes near 25 batches instead of paying 100 thread creation costs.
This is the exact architecture behind nginx's worker processes, Java's ThreadPoolExecutor, and Python's concurrent.futures.ThreadPoolExecutor , bounding concurrency to avoid the 'thread-per-request' collapse that took down early 2000s web servers under load spikes (the C10K problem). Getting shutdown wrong here mirrors a real operational hazard: failing to drain the queue before joining workers causes submitted work to be silently dropped in production job schedulers.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will implement enqueue, worker threads, and graceful shutdown. This exercise requires backpressure when the queue exceeds a max depth, matching how server frameworks cap pending work.
Implement thread pool with task queue.
Requirements:
Success Criteria:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github