add new work item to the pool
| 66 | |
| 67 | // add new work item to the pool |
| 68 | void ThreadPool::enqueue(std::function<void()> task) |
| 69 | { |
| 70 | { |
| 71 | std::unique_lock<std::mutex> lock(queue_mutex); |
| 72 | |
| 73 | // don't allow enqueueing after stopping the pool |
| 74 | if (stop) |
| 75 | throw std::runtime_error("enqueue on stopped ThreadPool"); |
| 76 | |
| 77 | tasks.emplace(task); |
| 78 | } |
| 79 | condition.notify_one(); |
| 80 | } |
| 81 | |
| 82 | // the destructor joins all threads |
| 83 | inline ThreadPool::~ThreadPool() |
no outgoing calls
no test coverage detected