Worker thread main loop
| 277 | |
| 278 | // Worker thread main loop |
| 279 | static void worker_thread(threadpool_data* owning_threadpool, std::size_t thread_id) |
| 280 | { |
| 281 | // store on the local thread data |
| 282 | create_threadpool_data(owning_threadpool, thread_id); |
| 283 | |
| 284 | // Set the wait handler so threads from the pool do useful work while |
| 285 | // waiting for another task to finish. |
| 286 | set_thread_wait_handler(threadpool_wait_handler); |
| 287 | |
| 288 | // Seed the random number generator with our id. This gives each thread a |
| 289 | // different steal order. |
| 290 | owning_threadpool->thread_data[thread_id].rng.seed(static_cast<std::minstd_rand::result_type>(thread_id)); |
| 291 | |
| 292 | // Prerun hook |
| 293 | if (owning_threadpool->prerun) owning_threadpool->prerun(); |
| 294 | |
| 295 | // Main loop, runs until the shutdown signal is recieved |
| 296 | thread_task_loop(owning_threadpool, thread_id, task_wait_handle()); |
| 297 | |
| 298 | // Postrun hook |
| 299 | if (owning_threadpool->postrun) owning_threadpool->postrun(); |
| 300 | } |
| 301 | |
| 302 | // Recursive function to spawn all worker threads in parallel |
| 303 | static void recursive_spawn_worker_thread(threadpool_data* impl, std::size_t index, std::size_t threads) |
no test coverage detected