title: C++11 multiple read and one write thread mutex
body: <p>I have an application, where some STL containers are read in 3 threads, and written in 2. I know there is TBB for multi-threaded containers, but it is not an option in my application. </p>
  
  <p>So I want to make the program thread-safe using std::mutex and my bare hands. This is a simple version of what I did: </p>
  
  <pre><code>int readers = 0;
  std::mutex write;
  
  // One write, no reads.
  void write_fun()
  {
      write.lock();// We lock the resource
      while(readers &gt; 0){}// We wait till everyone finishes read.
      // DO WRITE
      write.unlock();// Release
  }
  
  // Multiple reads, no write
  void read_fun()
  {
      // We wait if it is being written.
      while(!write.try_lock()){}
      write.unlock();
  
      readers++;
      // do read
      readers--;
  }
  </code></pre>
  
  <p>Is this the correct way to do this in C++11?</p>