mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Add soundness test for dropping scoped thread results before joining.
This commit is contained in:
parent
1c06eb7c1f
commit
b97d87518d
@ -4,10 +4,11 @@ use crate::mem;
|
|||||||
use crate::panic::panic_any;
|
use crate::panic::panic_any;
|
||||||
use crate::result;
|
use crate::result;
|
||||||
use crate::sync::{
|
use crate::sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
mpsc::{channel, Sender},
|
mpsc::{channel, Sender},
|
||||||
Arc, Barrier,
|
Arc, Barrier,
|
||||||
};
|
};
|
||||||
use crate::thread::{self, ThreadId};
|
use crate::thread::{self, Scope, ThreadId};
|
||||||
use crate::time::Duration;
|
use crate::time::Duration;
|
||||||
use crate::time::Instant;
|
use crate::time::Instant;
|
||||||
|
|
||||||
@ -293,3 +294,25 @@ fn test_thread_id_not_equal() {
|
|||||||
assert!(thread::current().id() != spawned_id);
|
assert!(thread::current().id() != spawned_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_scoped_threads_drop_result_before_join() {
|
||||||
|
let actually_finished = &AtomicBool::new(false);
|
||||||
|
struct X<'scope, 'env>(&'scope Scope<'scope, 'env>, &'env AtomicBool);
|
||||||
|
impl Drop for X<'_, '_> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
thread::sleep(Duration::from_millis(20));
|
||||||
|
let actually_finished = self.1;
|
||||||
|
self.0.spawn(move || {
|
||||||
|
thread::sleep(Duration::from_millis(20));
|
||||||
|
actually_finished.store(true, Ordering::Relaxed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
thread::scope(|s| {
|
||||||
|
s.spawn(move || {
|
||||||
|
thread::sleep(Duration::from_millis(20));
|
||||||
|
X(s, actually_finished)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
assert!(actually_finished.load(Ordering::Relaxed));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user