impl Drop for Msg { fn drop(&mutself) {
IS_RX.with(|is_rx: &Cell<_>| { // On `tx.send(msg)` returning `Err(msg)`, // we call `std::mem::forget(msg)`, so that // `drop` is not expected to be called in the // tx thread.
assert!(is_rx.get());
});
}
}
builder.check(|| { let (tx, rx) = oneshot::channel();
// tx thread let tx_thread_join_handle = thread::spawn(move || { // Ensure that `Msg::drop` in this thread will see is_rx == false
IS_RX.with(|is_rx: &Cell<_>| {
is_rx.set(false);
}); iflet Err(msg) = tx.send(Msg) {
std::mem::forget(msg);
}
});
// main thread is the rx thread
drop(rx);
tx_thread_join_handle.join().unwrap();
});
}
#[test] fn drop_rx_after_poll() { // Test that rx_task is properly deallocated when the receiver is dropped // after being polled (which sets rx_task), while the sender is concurrently // trying to send.
loom::model(|| { let (tx, mut rx) = oneshot::channel::<i32>();
// Poll once to set rx_task before entering the parallel part of the // test. let _ = block_on(poll_fn(|cx| { let _ = Pin::new(&mut rx).poll(cx);
Ready(())
}));
// Drop the receiver concurrently with the sender trying to send. let rx_thread = thread::spawn(move || {
drop(rx);
});
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.