title: Writing to file and mkdir race conditions C
body: <p>I made a function that tries to create a directory, and then write a simple file:</p>
  
  <pre><code>buffer = "Hello world!";
  string url = "a/b/c/d/";
  string tmp = "";
  string done = "";
  while((tmp = GetBaseDir(url)).compare("")!=0){
      done+=tmp;
      mkdir(done.c_str(), 0777);
  } // GetBaseDir returns "a/", and changes url to "b/c/d/"
  ofstream file;
  file.open((url+"file.txt").c_str(),ios::trunc);
  file &lt;&lt; buffer;
  file.close();
  </code></pre>
  
  <p>As you can see, it only tries, if there is a failure it just keeps going on.</p>
  
  <p>I read that 'open' will fail if another process opened that same file with write permissions. But, is this true?<br />
  What happens with mkdir and the write operation if I run several instances of this code at the same time?</p>