]>
git.proxmox.com Git - rustc.git/blob - vendor/rustc-rayon-core/tests/scoped_threadpool.rs
1 use crossbeam_utils
::thread
;
2 use rayon_core
::ThreadPoolBuilder
;
4 #[derive(PartialEq, Eq, Debug)]
7 scoped_tls
::scoped_thread_local
!(static LOCAL
: Local
);
10 fn missing_scoped_tls() {
11 LOCAL
.set(&Local(42), || {
12 let pool
= ThreadPoolBuilder
::new()
14 .expect("thread pool created");
16 // `LOCAL` is not set in the pool.
18 assert
!(!LOCAL
.is_set());
24 fn spawn_scoped_tls_threadpool() {
25 LOCAL
.set(&Local(42), || {
27 thread
::scope(|scope
| {
28 let pool
= ThreadPoolBuilder
::new()
29 .spawn_handler(move |thread
| {
33 // Borrow the same local value in the thread pool.
34 LOCAL
.set(x
, || thread
.run())
39 .expect("thread pool created");
41 // The pool matches our local value.
43 assert
!(LOCAL
.is_set());
49 // If we change our local value, the pool is not affected.
50 LOCAL
.set(&Local(-1), || {
52 assert
!(LOCAL
.is_set());
59 .expect("scope threads ok");
60 // `thread::scope` will wait for the threads to exit before returning.
66 fn build_scoped_tls_threadpool() {
67 LOCAL
.set(&Local(42), || {
69 ThreadPoolBuilder
::new()
71 move |thread
| LOCAL
.set(x
, || thread
.run()),
73 // The pool matches our local value.
75 assert
!(LOCAL
.is_set());
81 // If we change our local value, the pool is not affected.
82 LOCAL
.set(&Local(-1), || {
84 assert
!(LOCAL
.is_set());
92 .expect("thread pool created");
93 // Internally, `crossbeam::scope` will wait for the threads to exit before returning.