From ecf4e3cc3b8b7348c8097902de12198bcdf6825a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Lippai?= Date: Mon, 29 Nov 2021 22:02:33 +0100 Subject: [PATCH] Ability to terminate thread-pool upon shutdown While `.terminate()` will leave the thread-pool in corrupt state, it helps debugging and testing. --- rayon-core/src/thread_pool/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rayon-core/src/thread_pool/mod.rs b/rayon-core/src/thread_pool/mod.rs index 5edaedc37..f238b547e 100644 --- a/rayon-core/src/thread_pool/mod.rs +++ b/rayon-core/src/thread_pool/mod.rs @@ -277,11 +277,18 @@ impl ThreadPool { // We assert that `self.registry` has not terminated. unsafe { spawn::spawn_fifo_in(op, &self.registry) } } + + /// Terminates the threads, renders the threadpool unusable. + /// This is useful for testing (miri) if the thread-pool is static. + /// It should be used upon shutdown only + pub fn terminate(&mut self) { + self.registry.terminate(); + } } impl Drop for ThreadPool { fn drop(&mut self) { - self.registry.terminate(); + self.terminate(); } }