* Create "n_threads" workers, each with a dedicated task queue, and execute * the task as they arrive in the queues. **/
| 34 | * the task as they arrive in the queues. |
| 35 | **/ |
| 36 | ThreadPool(unsigned int n_threads = get_concurrency()) |
| 37 | : m_queues(n_threads), m_count(n_threads) { |
| 38 | assert(n_threads != 0); |
| 39 | auto worker = [&](unsigned int i) { |
| 40 | while (true) { |
| 41 | Proc f; |
| 42 | if (!m_queues[i].pop(f)) break; |
| 43 | f(); |
| 44 | } |
| 45 | }; |
| 46 | for (unsigned int i = 0; i < n_threads; ++i) |
| 47 | m_workers.emplace_back(worker, i); |
| 48 | } |
| 49 | |
| 50 | ~ThreadPool() noexcept { |
| 51 | for (auto& queue : m_queues) queue.done(); |
nothing calls this directly
no test coverage detected