|
What is the thread pool used for, and will it be used by Io vtable? I am wondering because I wish to have multiple threads, and have zio instance per thread. I would prefer if zio instance didn't need additional threads, but I also do not want the zio's event loop to be blocked. |
Replies: 1 comment 4 replies
|
The thread pool is essential for operations that do not have any native async API. For example, there is no way to asynchronously read a file on macOS/BSDs. So the read operations go through the thread pool. It's the sam model that e.g. libuv uses. You can avoid the thread on io_uring, but on every other system, it's not possible to get rid of it without blocking the event loop. I could make it possible to reuse a single thread pool for multiple instances, if you want to use it that way. For the edited out userdata question, all operations except for task spawning work based on the current scope. If you are running from within a task, they use the event loop. Otherwise they use blocking operation. So most vtable functions simply ignore the userdata. Operations will be submitted to the event loop where the task runs, irrespective of what io param you pass. And one more thing, if yiu want multiple instances, you need to create them in their corresponding threads. They can't move between threads, so you can't create 4 instances in the main thread and the pass them to the extra threads. |
The thread pool is essential for operations that do not have any native async API. For example, there is no way to asynchronously read a file on macOS/BSDs. So the read operations go through the thread pool. It's the sam model that e.g. libuv uses. You can avoid the thread on io_uring, but on every other system, it's not possible to get rid of it without blocking the event loop.
I could make it possible to reuse a single thread pool for multiple instances, if you want to use it that way.
For the edited out userdata question, all operations except for task spawning work based on the current scope. If you are running from within a task, they use the event loop. Otherwise they use blocking o…