diff --git a/rayon-core/src/thread_pool/test.rs b/rayon-core/src/thread_pool/test.rs index 88b36282d..1774d3d6b 100644 --- a/rayon-core/src/thread_pool/test.rs +++ b/rayon-core/src/thread_pool/test.rs @@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::mpsc::channel; use std::sync::{Arc, Mutex}; +use std::thread; use crate::{join, Scope, ScopeFifo, ThreadPool, ThreadPoolBuilder}; @@ -381,6 +382,43 @@ fn in_place_scope_fifo_no_deadlock() { }); } +#[test] +#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)] +fn scope_in_place_which_pool() { + let pool = ThreadPoolBuilder::new() + .num_threads(7) + .thread_name(|_| "worker".to_owned()) + .build() + .unwrap(); + + pool.in_place_scope(|scope| { + // Determine which pool is currently installed here by checking the thread name seen by spawned work items. + let (name_send, name_recv) = channel(); + + scope.spawn(move |_| { + let name = thread::current().name().map(ToOwned::to_owned); + + name_send.send(name).unwrap(); + }); + + let name = name_recv.recv().unwrap(); + + assert_eq!(name.as_deref(), Some("worker")); + + let (name_send, name_recv) = channel(); + + crate::spawn(move || { + let name = thread::current().name().map(ToOwned::to_owned); + + name_send.send(name).unwrap(); + }); + + let name = name_recv.recv().unwrap(); + + assert_eq!(name.as_deref(), Some("worker")); + }); +} + #[test] fn yield_now_to_spawn() { let (tx, rx) = channel();