Skip to content

Commit

Permalink
runtime: mark JoinHandle as UnwindSafe (tokio-rs#4414)
Browse files Browse the repository at this point in the history
Hodkinson committed Jan 23, 2022
1 parent 9a57a6a commit debbbb7
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tokio/src/runtime/task/join.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use crate::runtime::task::RawTask;
use std::fmt;
use std::future::Future;
use std::marker::PhantomData;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::pin::Pin;
use std::task::{Context, Poll};

@@ -150,6 +151,9 @@ cfg_rt! {
unsafe impl<T: Send> Send for JoinHandle<T> {}
unsafe impl<T: Send> Sync for JoinHandle<T> {}

impl<T: Send> UnwindSafe for JoinHandle<T> {}
impl<T: Send> RefUnwindSafe for JoinHandle<T> {}

impl<T> JoinHandle<T> {
pub(super) fn new(raw: RawTask) -> JoinHandle<T> {
JoinHandle {
16 changes: 16 additions & 0 deletions tokio/tests/net_types_unwind.rs → tokio/tests/unwindsafe.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,22 @@
#![cfg(feature = "full")]

use std::panic::{RefUnwindSafe, UnwindSafe};
use tokio::task::spawn_blocking;

#[tokio::test]
async fn futures_are_unwind_safe() {
unwind_safe_future(|| async {
let _ = spawn_blocking(|| {}).await;
})
.await
}

async fn unwind_safe_future<F, Fut>(_: F)
where
F: FnOnce() -> Fut,
Fut: std::future::Future<Output = ()> + std::panic::UnwindSafe,
{
}

#[test]
fn net_types_are_unwind_safe() {

0 comments on commit debbbb7

Please sign in to comment.