title: c++ fstream concurrent access
body: <p>What will happen if files are accessed concurrently from different processes/threads?
  I understand there is no standard way of locking a file, only os specific functions.</p>
  
  <p>In my case files will be read often and written seldom.
  Now if <code>A</code> open a file for reading (ifstream) and starts reading chunks. And <code>B</code> opens the same file for writing (ofstream) and starts writing. What will happen? Is there a defined behavior?</p>
  
  <p><strong>edit</strong>
  My goal is concurrent read, write access to many files. But write access will not occur very often. I would be content if the fstreams guarantee that file content doesn't get mixed up.</p>
  
  <p>E.g.:
  Process 1 and 2 write to file A. If they write concurrently I dont't care if the version of 1 or 2 is written to disc, as long as it is a consistent version of the file.</p>
  
  <p>If a process reads a file and another writes to it at the same time, I want the reading process to get the "old" version of the file.</p>
  
  <p>If fstreams don't handle this I will use a database.</p>