Quote:
Originally Posted by
wipe3out
> Corona688
> achenle
Thank you for answering my question.
is that mean, in the other words, when fread/fwrite called at the same time on same chunk of the file, both function call doesn't return an error but the result of fread would be unpredictable...is that right??
Exactly. Unless you use some form of locking, the order is unpredictable.
Quote:
So actual device I/O may not occur at the same time as fwrite/fread function is called, isn't it? Can I trust operating system to sync the data passed to fwrite on the disk certainly in spite of the fact that fread is called simultaneously?
You can't trust fwrite() to sync at all, unless you fflush() after.
Quote:
now I think that I almost understand what happening behind the fread/fwrite anyway.
What fwrite does is call write(), if it has enough data, otherwise it just stores it to write later.
write() and read() are the actual system calls. They're not library functions, there's no deeper inside your program to go. At the point they get called, your program literally just stops until the kernel's done its job. So it's the kernel which decides what order they run in, and it won't enforce any particular order unless you've told it to.