-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Expose current thread pool via the interface of
ThreadPool
to …
…allow reifying the ambient capability
- Loading branch information
1 parent
326fd64
commit 8289ada
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use rayon::prelude::*; | ||
use rayon::{ThreadPool, ThreadPoolBuilder}; | ||
use std::thread; | ||
|
||
#[test] | ||
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)] | ||
fn with_current() { | ||
fn high_priority_work() { | ||
assert_eq!(thread::current().name(), Some("high-priority-thread")); | ||
} | ||
|
||
fn regular_work(_item: &()) { | ||
assert_eq!(thread::current().name(), None); | ||
} | ||
|
||
let items = vec![(); 128]; | ||
|
||
let default_pool = ThreadPool::current(); | ||
|
||
let high_priority_pool = ThreadPoolBuilder::new() | ||
.thread_name(|_| "high-priority-thread".to_owned()) | ||
.build() | ||
.unwrap(); | ||
|
||
high_priority_pool.in_place_scope(|scope| { | ||
scope.spawn(|_| high_priority_work()); | ||
|
||
default_pool.with_current(|| { | ||
items.par_iter().for_each(|item| regular_work(item)); | ||
}) | ||
}); | ||
} |