While looking for a duplicate for this question I started to wonder about what would happen if the peer closes the connection, or if there's a network error.
This is the scenario:
A program which uses a TCP connection, and uses two threads:
- One thread that calls
read
orrecv
;- And one thread that calls
write
orsend
If the peer closes the connection the behavior for the two threads would be different and there are no guarantees which of the threads would be the first to detect the event.
I also haven't seen anything about events like connection closes by peer, or network error events, being atomic.
Are peer closing the connection as well as error handling for multi-threaded processes specified by POSIX? Will the behavior of a process like in the describes scenario be well-defined?