MCPcopy Create free account
hub / github.com/Amanieu/asyncplusplus / worker_thread

Function worker_thread

src/threadpool_scheduler.cpp:279–300  ·  view source on GitHub ↗

Worker thread main loop

Source from the content-addressed store, hash-verified

277
278// Worker thread main loop
279static 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
303static void recursive_spawn_worker_thread(threadpool_data* impl, std::size_t index, std::size_t threads)

Callers 1

Calls 4

create_threadpool_dataFunction · 0.85
set_thread_wait_handlerFunction · 0.85
thread_task_loopFunction · 0.85
task_wait_handleClass · 0.85

Tested by

no test coverage detected