How to mix thread and asio?

34 Views Asked by At

As far as I know, a coroutine should not have blocking code. But some third party libraries have blocking code, so if I want to use them in a coroutine without blocking the current coroutine, shouldn't I use a thread? The thread executes completely and then resumes the coroutine. How do I do that, is asio::post ok? The documentation seems to be missing the most crucial thing. The documentation only says that asio::post executes asynchronous code, is this asynchronous code executed in a different thread than the other conroutine? If not, then if this code is blocking, won't it also block other coroutines? If I use thread, there should be no way to call join in the thread, because it block the current coroutine. If I execute resume in the thread, I heard that this doesn't work because resume shouldn't be executed in a different thread than the one executing io_context::run. Is this true? I've searched the whole web and even asked copilot and got no answer, does no one care about this?

0

There are 0 best solutions below