What would happen if you call read
(or write
, or both) in two different thread, on the same file descriptor (lets says we are interested about a lo
Any system level (syscall) file descriptor access is thread safe in all mainstream UNIX-like OSes. Though depending on the age they are not necessarily signal safe.
If you call read
, write
, accept
or similar on a file descriptor from two different tasks then the kernel's internal locking mechanism will resolve contention.
For reads each byte may be only read once though and writes will go in any undefined order.
The stdio library functions fread
, fwrite
and co. also have by default internal locking on the control structures, though by using flags it is possible to disable that.