Capstone C: a concurrent job runner
The third capstone of the Haskell course builds a concurrent job runner in eight lessons. A job has an id and a command, a bounded STM queue holds it, and a pool of workers takes it and puts the result in a channel. The last lessons collect the results, stop the pool cleanly, log without a race, test the concurrency, and measure the pool with one worker against four.
119
Capstone C: the job model
a job with an id and a command, a result, Show
Open
120
Capstone C: the STM queue
TVar [Job], retry, a bounded queue, a producer that stops
Open
121
Capstone C: the workers
a pool of forkIO threads, the result channel, a worker that dies
Open
122
Capstone C: results and totals
collect the results, a summary, the order that STM does not promise
Open
123
Capstone C: a clean shutdown
a stop flag in a TVar, orElse, waiting for every worker
Open
124
Capstone C: logging without a race
one logger thread, a channel of lines, the order of the log
Open
125
Capstone C: testing concurrency
a deterministic test with one worker, a repeated test, the flakiness that is real
Open
126
Capstone C: measuring the pool
-threaded, five runs, min and median, one worker against four
Open