summaryrefslogtreecommitdiffstats
path: root/vendor/crossbeam-channel/tests/thread_locals.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/crossbeam-channel/tests/thread_locals.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--vendor/crossbeam-channel/tests/thread_locals.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/crossbeam-channel/tests/thread_locals.rs b/vendor/crossbeam-channel/tests/thread_locals.rs
new file mode 100644
index 000000000..effb6a143
--- /dev/null
+++ b/vendor/crossbeam-channel/tests/thread_locals.rs
@@ -0,0 +1,53 @@
+//! Tests that make sure accessing thread-locals while exiting the thread doesn't cause panics.
+
+#![cfg(not(miri))] // error: abnormal termination: the evaluated program aborted execution
+
+use std::thread;
+use std::time::Duration;
+
+use crossbeam_channel::{select, unbounded};
+use crossbeam_utils::thread::scope;
+
+fn ms(ms: u64) -> Duration {
+ Duration::from_millis(ms)
+}
+
+#[test]
+#[cfg_attr(target_os = "macos", ignore = "TLS is destroyed too early on macOS")]
+fn use_while_exiting() {
+ struct Foo;
+
+ impl Drop for Foo {
+ fn drop(&mut self) {
+ // A blocking operation after the thread-locals have been dropped. This will attempt to
+ // use the thread-locals and must not panic.
+ let (_s, r) = unbounded::<()>();
+ select! {
+ recv(r) -> _ => {}
+ default(ms(100)) => {}
+ }
+ }
+ }
+
+ thread_local! {
+ static FOO: Foo = Foo;
+ }
+
+ let (s, r) = unbounded::<()>();
+
+ scope(|scope| {
+ scope.spawn(|_| {
+ // First initialize `FOO`, then the thread-locals related to crossbeam-channel.
+ FOO.with(|_| ());
+ r.recv().unwrap();
+ // At thread exit, thread-locals related to crossbeam-channel get dropped first and
+ // `FOO` is dropped last.
+ });
+
+ scope.spawn(|_| {
+ thread::sleep(ms(100));
+ s.send(()).unwrap();
+ });
+ })
+ .unwrap();
+}