October 2013
Intermediate to advanced
368 pages
9h 20m
English
Our hypothesis this time is that the spurious failures are caused by data contention around the work queue. The main thread adds to the work queue, the
pullWork
function removes from the queue, and the worker often asks whether there’s work available in the queue.
Our tests aren’t simply failing; they are generating segmentation faults. Concurrent modification of the work queue is the likely suspect. As an attempt at remediation, we first write a test that consistently generates the same failure.
| c9/10/ThreadPoolTest.cpp | |
| | TEST_GROUP(AThreadPool_AddRequest) { |
| | mutex m; |
| | ThreadPool pool; |
| | condition_variable wasExecuted; |
| | unsigned int count{0}; |
| | |
| * | vector<shared_ptr<thread>> threads; |
| | |
| | void setup() ... |