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

Function recursive_spawn_worker_thread

src/threadpool_scheduler.cpp:303–321  ·  view source on GitHub ↗

Recursive function to spawn all worker threads in parallel

Source from the content-addressed store, hash-verified

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)
304{
305 // If we are down to one thread, go to the worker main loop
306 if (threads == 1)
307 worker_thread(impl, index);
308 else {
309 // Split thread range into 2 sub-ranges
310 std::size_t mid = index + threads / 2;
311
312 // Spawn a thread for half of the range
313 impl->thread_data[mid].handle = std::thread(recursive_spawn_worker_thread, impl, mid, threads - threads / 2);
314#ifdef BROKEN_JOIN_IN_DESTRUCTOR
315 impl->thread_data[mid].handle.detach();
316#endif
317
318 // Tail-recurse to handle our half of the range
319 recursive_spawn_worker_thread(impl, index, threads / 2);
320 }
321}
322
323} // namespace detail
324

Callers

nothing calls this directly

Calls 1

worker_threadFunction · 0.85

Tested by

no test coverage detected