Open Kestrer opened 3 years ago
I don't know, this feels like it would be an easy footgun to accidentally set off. See the issues with #59
Yeah, both of the currently submitted PRs seem to cause problems with the existing code when the threads are disabled.
@taiki-e Do you mind if I close this as well as #59? At worst, all the async-io
thread will do is idle on the reactor lock and occasionally pick up slack. Even in those cases, it can prevent programs from grinding to a halt. The only reason I can think of to plan this is if we wanted to port smol
to no_std
for some reason.
Yeah, theoretically it would be more efficient to have no threads, but I don't see this as some kind of bug or problem that needs to be fixed in the near future.
Reopening this as apparently this is a sticking point for some users
For the single thread use case, we can get around the pre-emption deadlock by having the block_on
call just refuse to give up the reactor lock if it sees that BLOCK_ON_COUNT
is equal to 1. Then we only spawn the reactor thread once BLOCK_ON_COUNT
is bumped to 2 or if an asynchronous resource is used with no block on threads.
For the multi threaded use cases, this definitely requires more thought and synchronization. Possibly so much synchronization that it stops being worth it. This requires more thought and benchmarking... especially since the current reactor is especially stable and I don't want to rock that boat too hard.
I'd accept a PR for the single threaded use case.
I'd be interested in a way to shut down the spawned thread if there is one. I have a use case where I want to dl_close a DLL, and I need to make sure all the threads using the code are gone. I know it's a bit different from what this is asking for, but it's related.
I have a use case where I want to dl_close a DLL, and I need to make sure all the threads using the code are gone. I know it's a bit different from what this is asking for, but it's related.
Maybe a shutdown_reactor
function would be nice here, for people who know what they are doing.
In most programs that use
async-io
, the user will simply runblock_on
at the top level. However, this will still spawn theasync-io
thread despite it not being necessary. Would it be possible to avoid that?