pread itself is thread safe because it is not in the list of unsafe functions . So it can be called safe.
The real question is: what happens if you read the same file at the same time (not necessarily from two threads, but also from two processes).
Regarding this, the specification says:
The behavior of multiple concurrent reads on the same channel, FIFO, or terminal device is not specified.
Please note that it does not mention regular files. This bit only applies to read in any case, because pread cannot be used in files with unspeakable files.
I / O is for atomic regular files and channels and FIFOs.
But this is from a non-normative section, so your OS may do it differently. For example, if you are reading from two streams and there is simultaneous writing, you can get different parts of the writing in your two reading buffers. But such a problem is not specific to multithreading.
Itβs also nice to know that in some cases
read () blocks the calling thread
Not a process, just a stream. AND
A thread that is blocked should not prevent an unlocked thread [...] from moving forward.
source share