mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
67e49f190c
This commit changes how `std.io.poll` is implemented on Windows. The new implementation unfortunately incurs a little extra system call overhead, but fixes a major bug in the old implementation. I'm not yet set on this implementation, but I'm pushing it to check if it resolves my CI failures. The old implementation was buggy in that by leaving `ReadFile` calls into the `LinearFifo` write end pending between `poll` calls, there was potential for a race condition where the kernel satisfies the asynchronous read after the caller has modified the corresponding `LinearFifo` in some way; most likely by rotating its buffer for a `readableSliceOfLen` call. The only way to allow the full `LinearFifo` API to be used is to not leave these `ReadFile` calls pending after `poll` returns. So, now, `pollWindows` will leave running a different set of `ReadFile` calls, which are trying to read a single byte into a temporary buffer. These are the operations we wait on with `WaitForMultipleObjects`. When these reads are completed, we push that single byte to the FIFO, and perform some reads directly into the FIFO memory until we stop getting immediate results; then, we again queue a single-byte read into a stable buffer for the next call to `poll`. My main concern with this implementation is that if the kernel frequently returns `IO_PENDING` for `ReadFile` calls even when the data is available, then we could effectively skip the bulk-reading path, hence reading data one byte at a time. Performance measurements are necessary here. |
||
---|---|---|
.. | ||
compiler | ||
compiler_rt | ||
docs | ||
fuzzer/web | ||
include | ||
init | ||
libc | ||
libcxx | ||
libcxxabi | ||
libunwind | ||
std | ||
tsan | ||
c.zig | ||
compiler_rt.zig | ||
fuzzer.zig | ||
zig.h |