I have several requests related to read () / pread () system calls in a multi-threaded environment
I use Mac-OSX, which is based on freeBsd, if that helps anyway I use this file only in read mode, not read / write AND c / C ++ language
Suppose we have a file on drive AAAABBBBCCCCDDDEEEE ....
and 4 alphabets correspond to one page of the file
So, Page1: AAAA
Page 2: BBBB ..... etc.
now i am starting to read a system call from two different threads with the same file descriptor my intention is to read the first page from stream 1, the second page from stream 2, ... etc.
read (FD, positive effect, SizeOf (pages));
From the man page I was given to understand that reading also increases the pointer to the file, so I definitely get distorted answers, for example
ABCC ABBB .. etc. (without a specific sequence)
to fix this i can use pread ()
"Pread () performs the same function, but reads from the fied specification in a file without changing the file pointer" // from man pages
But I'm not sure if using pread really helps me in my goal, because even if it does not increase the internal file pointer, there is no guarantee that the answers will not be mixed up.
All my data is page aligned and I want to read one page from each stream, for example
Theme 1 reads: AAAA Theme 2 reads: BBBB Theme 3 reads: UDP ... without actually distorting the content.
I also found the message Is it safe to read () from a file as soon as write () returns?
but it was not very helpful.
I'm also not sure if read () will really have the problem I'm thinking of. The file I am reading is a binary file, and therefore it is difficult for me to simply read and check manually quickly.
Any help would be appreciated