title: Checking whether a file is being written to with std::fstream
body: <p>I am writing to, and reading from, a file called "results.dat", using <code>std::fstream</code>. This is done asynchronously, with the "read" and "write" function running in entirely different C++ programs. I want to check that the file is not currently being read before I write to it.</p>
  
  <p>Suppose that my data is an array of 10 floats, then my "write" function looks like:</p>
  
  <pre><code>std::ofstream file_out("results.dat", std::ios::binary | std::ios::trunc);
  file_out.write((char*)&amp;data, 10 * sizeof(float));
  file_out.close();
  </code></pre>
  
  <p>And my "read" function looks like:</p>
  
  <pre><code>std::ifstream file_in("results.dat", std::ios::binary);
  file_in.read((char*)&amp;data, 10 * sizeof(float));
  file_in.close();
  </code></pre>
  
  <p>If the file "results.dat" is currently being read, I then want to make my "write" function wait, in a loop, until it is no longer being read. How can I implement this?</p>