Please assume below scenario (OS = Redhat Linux),
Option A :
Writer Thread : Writes to a file using FD=1. Sets last written position and size in a std::atomic<int64_t> variable.
Edit for more clarity : write done using write C function call. https://www.man7.org/linux/man-pages/man2/write.2.html
Reader Thread : Reads above file using a different FD=2 at value saved in above std::atomic<int64_t> variable.
Then I presume it is possible that, above read thread NOT being able to read all data written by the writer thread (i.e. a read call with FD=2 could return a lesser no of bytes). Since there could be buffering at FD level.
======================================================================================
Option B:
Writer Thread : Writes to a file using FD=1. Sets last written position and size in a std::atomic<int64_t> variable.
Edit for more clarity : Only appends done (no overwrite takes place).write done using write C function call. https://www.man7.org/linux/man-pages/man2/write.2.html
Reader Thread : Reads(using pread) above file using the same FD=1 at value saved in above std::atomic<int64_t> variable.
https://man7.org/linux/man-pages/man2/pwrite.2.html
Now, is it guaranteed that ALL data written by Writer thread is read by Reader Thread ?