the constructor just launches some amount of workers
| 29 | |
| 30 | // the constructor just launches some amount of workers |
| 31 | inline ThreadPool::ThreadPool(size_t threads) |
| 32 | : stop(false) |
| 33 | { |
| 34 | for (size_t i = 0; i < threads; ++i) |
| 35 | workers.emplace_back( |
| 36 | [this] |
| 37 | { |
| 38 | for (;;) |
| 39 | { |
| 40 | std::packaged_task<void()> task; |
| 41 | |
| 42 | { |
| 43 | std::unique_lock<std::mutex> lock(this->queue_mutex); |
| 44 | this->condition.wait(lock, |
| 45 | [this] { return this->stop || !this->tasks.empty(); }); |
| 46 | if (this->stop && this->tasks.empty()) |
| 47 | return; |
| 48 | task = std::move(this->tasks.front()); |
| 49 | this->tasks.pop(); |
| 50 | } |
| 51 | |
| 52 | task(); |
| 53 | } |
| 54 | } |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | // add new work item to the pool |
| 59 | template<class F, class... Args> |
nothing calls this directly
no test coverage detected