
Issue #19642 has been updated by ioquatix (Samuel Williams). Thanks Nakamura-san for your feedback. According to POSIX:
Atomic/non-atomic: A write is atomic if the whole amount written in one operation is not interleaved with data from any other process. This is useful when there are multiple writers sending data to a single reader. Applications need to know how large a write request can be expected to be performed atomically. This maximum is called {PIPE_BUF}. This volume of IEEE Std 1003.1-2001 does not say whether write requests for more than {PIPE_BUF} bytes are atomic, but requires that writes of {PIPE_BUF} or fewer bytes shall be atomic.
I assume since `writev` is defined in terms of `write`, that `writev` of total size <= `PIPE_BUF` will be atomic. It is not defined what happens when the size is bigger than `PIPE_BUF`, but we can assume it is non-atomic. Since we already have a write lock in `IO`, writes should be atomic at the Ruby IO level. But not at the kernel level and not between processes that share the same pipes. ``` irb(main):001:0> $stderr.sync => true irb(main):002:0> $stdout.sync => true ``` It looks like `$stdout` and `$stderr` are both buffered internally. I think Ruby should guarantee buffered writes will be atomic up to PIPE_BUF. Unbuffered writes should have no atomicity guarantees. If it's not documented, maybe we can consider adding that. ---------------------------------------- Feature #19642: Remove vectored read/write from `io.c`. https://bugs.ruby-lang.org/issues/19642#change-103151 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal * Assignee: ioquatix (Samuel Williams) ---------------------------------------- https://github.com/socketry/async/issues/228#issuecomment-1546789910 is a comment from the kernel developer who tells us that `writev` is always worse than `write` system call. A large amount of complexity in `io.c` comes from optional support from `writev`. So, I'd like to remove support for `writev`. I may try to measure the performance before/after. However it may not show much difference, except that the implementation in `io.c` can be much simpler. -- https://bugs.ruby-lang.org/