I've got an application written in C++ (Project Builder). It has about 8 threads within a single process. All the threads are reading from the same disk file. It is a huge disk file, each thread is reading a different section of the file.
Each thread opens the file with fopen() and gets a unique FILE stream, with a unique IO buffer (at least, the 4,096 byte buffer within the FILE object is unique .. each thread has a unique address for this).
The threads do an fseek() and fread() to read data from the disk file. Each thread _appears_ to have a uniuque stream.
But the threads do not produce good results: the data read from the disk is not the expected data. It appears that there is some kind of low-level disk buffering going on that precludes multiple threads from reading a single disk file.
Certainly this has been done before: multiple threads (within a single process) _must_ be able to read from a single disk file (via mulitple streams), true?
Question: Is there any way to make this work? For example, is there some flag or option I can turn on to make the stream (fopen(), fseek() fread() etc) functions thread-safe?
Each thread opens the file with fopen() and gets a unique FILE stream, with a unique IO buffer (at least, the 4,096 byte buffer within the FILE object is unique .. each thread has a unique address for this).
The threads do an fseek() and fread() to read data from the disk file. Each thread _appears_ to have a uniuque stream.
But the threads do not produce good results: the data read from the disk is not the expected data. It appears that there is some kind of low-level disk buffering going on that precludes multiple threads from reading a single disk file.
Certainly this has been done before: multiple threads (within a single process) _must_ be able to read from a single disk file (via mulitple streams), true?
Question: Is there any way to make this work? For example, is there some flag or option I can turn on to make the stream (fopen(), fseek() fread() etc) functions thread-safe?