Advanced · Module 11 · Lesson 5 of 6
Project: A Producer-Consumer Task Queue
Assemble a fixed thread pool around a guarded task queue, where producers submit jobs and consumers drain them until done and join.
By the end you can
- Assemble a thread pool with producers, consumers and clean shutdown
- Submit tasks through a guarded queue with condition notification
- Verify shutdown with done flag, notify all and joined workers
Builds on Condition Variables: Waiting for Work.
01 · A question first
An image service receives forty resize jobs from three upload handlers while four workers drain a shared queue. Idle workers sleep, active workers pop one task at a time, and the service stops only after the last job finishes and every worker has been joined. How do submission, sleep and shutdown fit in one class?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Start with the pool
- How the idea works
- A print shop
- Why it is correct
- Pitfalls and variations
- Complete solution
- Where it is used and what comes next
03 · Practice
Something wrong with this lesson? Report a problem