diff --git a/rayon-core/src/registry.rs b/rayon-core/src/registry.rs index 72fc86a69..2b48394b9 100644 --- a/rayon-core/src/registry.rs +++ b/rayon-core/src/registry.rs @@ -947,18 +947,15 @@ unsafe fn main_loop(thread: ThreadBuilder) { registry.catch_unwind(|| handler(index)); } - let my_terminate_latch = ®istry.thread_infos[index].terminate; worker_thread.log(|| ThreadStart { worker: index, - terminate_addr: my_terminate_latch.as_core_latch().addr(), + terminate_addr: registry.thread_infos[index] + .terminate + .as_core_latch() + .addr(), }); - worker_thread.wait_until(my_terminate_latch); - // Should not be any work left in our queue. - debug_assert!(worker_thread.take_local_job().is_none()); - - // let registry know we are done - Latch::set(®istry.thread_infos[index].stopped); + wait_until_out_of_work(worker_thread); // Normal termination, do not abort. mem::forget(abort_guard); @@ -972,6 +969,20 @@ unsafe fn main_loop(thread: ThreadBuilder) { } } +unsafe fn wait_until_out_of_work(worker_thread: &WorkerThread) { + debug_assert_eq!(worker_thread as *const _, WorkerThread::current()); + let registry = &*worker_thread.registry; + let index = worker_thread.index; + + worker_thread.wait_until(®istry.thread_infos[index].terminate); + + // Should not be any work left in our queue. + debug_assert!(worker_thread.take_local_job().is_none()); + + // let registry know we are done + Latch::set(®istry.thread_infos[index].stopped); +} + /// If already in a worker-thread, just execute `op`. Otherwise, /// execute `op` in the default thread-pool. Either way, block until /// `op` completes and return its return value. If `op` panics, that