-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JoinHandle.await
in another thread has chance to block forever.
#241
Comments
The main issue here is that you run it on mac os, so you do not have any guarantee on where the task is going to be ran (on which core it's going to be executed). That why you have an erratic behavior. For this part, you can activate the |
@Miaxos The doc does not provide any clue about how to use Another issue is that if the task panics, the |
Hey @drmingdrmer I took some time to provide you an example of a working solution without (To be able to run those tests & io-uring using macos, I suggest you run those inside a VM backed by tart, it's what I'm using and it's working very well). A working solution without `sync` (Linux only)(If you change the pinned thread, it won't work without the use std::sync::mpsc;
use std::time::Duration;
fn main() {
let (tx, rx) = mpsc::channel();
let t1 = std::thread::spawn(move || {
// If you want to force a thread to be pinned on a core
// (Only available on linux)
monoio::utils::bind_to_cpu_set(Some(0)).unwrap();
let mut rt = monoio::RuntimeBuilder::<monoio::FusionDriver>::new()
.enable_all()
.build()
.unwrap();
rt.block_on(async move {
let fu = async move {
println!("inner-fu: ready");
1u64
};
let handle = monoio::spawn(fu);
tx.send(handle).unwrap();
monoio::time::sleep(Duration::from_millis(1_000)).await;
println!("outer-fu: after sending handle and sleep");
});
});
let t2 = std::thread::spawn(move || {
// If you want to force a thread to be pinned on a core
// (Only available on linux)
monoio::utils::bind_to_cpu_set(Some(0)).unwrap();
let mut rt = monoio::RuntimeBuilder::<monoio::FusionDriver>::new()
.enable_all()
.build()
.unwrap();
rt.block_on(async move {
println!("joiner: before handle.await");
loop {
if let Ok(handle) = rx.try_recv() {
let got = handle.await;
println!("joiner: after handle.await: {:?}", got);
break;
}
}
});
});
t1.join().unwrap();
t2.join().unwrap();
}
Based on the implementation, you'll need to have
Yeah, right now you would need to wrap future spawned into a |
Version
monoio v0.2.2
Platform
Description
Calling
JoinHandle.await
in another thread(and also in another monoio runtime), it has odd to return the expected value and odd to block forever.The code to reproduce this issue is in the following repo:
https://github.com/drmingdrmer/t-monoio/blob/ec306d33e9f581eacd06c51034de7d0d4698f9dd/src/bin/cross-rt-join.rs#L1
It is quite simple. Create a monoio runtime to run a future, send the JoinHandle to another thread and
await
it in another monoio runtime:Clone it and run it with:
Sometimes it blocks forever:
Sometime it returns the expected value:
The text was updated successfully, but these errors were encountered: