October 2013
Intermediate to advanced
368 pages
9h 20m
English
(Note: CppUTest’s memory leak detector is not currently thread-safe. You will want to turn it off for this exercise only; see http://www.cpputest.org/node/25 for further information. Turning off memory leak detection will cause problems when coding the exercise in Chapter 8, Legacy Challenges.)
We want ThreadPool to handle pulling and executing work on its own. We’ll need a thread. We create a test that shows how we want to send a Work object to the ThreadPool’s
add
function and let the pool execute the work asynchronously.
| c9/6/ThreadPoolTest.cpp | |
| | TEST(AThreadPool, PullsWorkInAThread) { |
| | pool.start(); |
| | condition_variable wasExecuted; |
| | bool wasWorked{0}; |
| | Work work{[&] { |
| | unique_lock<mutex> lock(m); |
| | wasWorked ... |