Writing has the side effect of changing the file and multiple writers racing to write into the same file are not uncommon. Writing and reading the file simultaneously is also a common use case. The standard basically says that overflow()
makes write()
syscall (as opposed to buffered fwrite()
) to delegate synchronization to the operating system.
Reading has no side effects for files (it may update atime to be pedantic), multiple readers do not race with each other so that no synchronization is necessary.
Reading a pipe or socket, on the other hand, has a side effect of changing the contents of the underlying buffer. However, readers competing to read from the same pipe, TCP or stream UNIX socket do not make much sense. It may make sense for datagram sockets, but I am not sure if IOStreams being streams are designed to work with datagram sockets. I gather the standard writers could not come up with a good use case for read synchronization and hence left it unspecified.