Avatar
omochimetaru 9/16/2022 6:35 AM
これじゃあスレッド爆発か先行処理待ちが起きてしまう
6:36 AM
/// `NonBlockingFileIO` is a helper that allows you to read files without blocking the calling thread. /// /// It is worth noting that `kqueue`, `epoll` or `poll` returning claiming a file is readable does not mean that the /// data is already available in the kernel's memory. In other words, a `read` from a file can still block even if /// reported as readable. This behaviour is also documented behaviour: /// /// - [`poll`](http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html): "Regular files shall always poll TRUE for reading and writing." /// - [`epoll`](http://man7.org/linux/man-pages/man7/epoll.7.html): "epoll is simply a faster poll(2), and can be used wherever the latter is used since it shares the same semantics." /// - [`kqueue`](https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2): "Returns when the file pointer is not at the end of file." /// /// `NonBlockingFileIO` helps to work around this issue by maintaining its own thread pool that is used to read the data /// from the files into memory. It will then hand the (in-memory) data back which makes it available without the possibility /// of blocking.
6:37 AM
It is worth noting that kqueue, epoll or poll returning claiming a file is readable does not mean that the data is already available in the kernel's memory. In other words, a read from a file can still block even if reported as readable. This behaviour is also documented behaviour
6:37 AM
pollがreadableを返したとしても、その直後にreadをするとブロッキングされる事がある!?