#[test] #[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)] fn missing_scoped_tls() {
LOCAL.set(&Local(42), || { let pool = ThreadPoolBuilder::new()
.build()
.expect("thread pool created");
// `LOCAL` is not set in the pool.
pool.install(|| {
assert!(!LOCAL.is_set());
});
});
}
#[test] #[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)] fn spawn_scoped_tls_threadpool() {
LOCAL.set(&Local(42), || {
LOCAL.with(|x| {
thread::scope(|scope| { let pool = ThreadPoolBuilder::new()
.spawn_handler(move |thread| {
scope
.builder()
.spawn(move |_| { // Borrow the same local value in the thread pool.
LOCAL.set(x, || thread.run())
})
.map(|_| ())
})
.build()
.expect("thread pool created");
// The pool matches our local value.
pool.install(|| {
assert!(LOCAL.is_set());
LOCAL.with(|y| {
assert_eq!(x, y);
});
});
// If we change our local value, the pool is not affected.
LOCAL.set(&Local(-1), || {
pool.install(|| {
assert!(LOCAL.is_set());
LOCAL.with(|y| {
assert_eq!(x, y);
});
});
});
})
.expect("scope threads ok"); // `thread::scope` will wait for the threads to exit before returning.
});
});
}
// If we change our local value, the pool is not affected.
LOCAL.set(&Local(-1), || {
pool.install(|| {
assert!(LOCAL.is_set());
LOCAL.with(|y| {
assert_eq!(x, y);
});
});
});
},
)
.expect("thread pool created"); // Internally, `std::thread::scope` will wait for the threads to exit before returning.
});
});
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.