Open drmingdrmer opened 8 months ago
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. You could run it on linux and pin specific core to those thread and you would be able to have it working each time or failing each time.
For this part, you can activate the sync
feature flag on monoio and you'll be able to do cross-thread async communication documented here (but it would be better in term of performance if you avoided cross-thread async communication as it's way more efficient when you avoid it)
@Miaxos
Thank you so much! it looks like the sync
feature flag is the cause. With sync
enabled, the program outputs consistent result.
The doc does not provide any clue about how to use JoinHandle
correctly in another thread.
Is it possible to remove the Send
and Sync
bound from JoinHandle
if sync
feature flag is not enabled?
Another issue is that if the task panics, the JoinHandle.await
in another thread blocks forever.
Hey @drmingdrmer I took some time to provide you an example of a working solution without sync
. If you change the pinned core, the solution won't work anymore without sync
.
(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).
Is it possible to remove the Send and Sync bound from JoinHandle if sync feature flag is not enabled?
Based on the implementation, you'll need to have T: !Send
for JoinHandle<T>
to not be Send
.
Another issue is that if the task panics, the JoinHandle.await in another thread blocks forever.
Yeah, right now you would need to wrap future spawned into a catch_unwind
with a manual Result
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: