title: How to asynchronously read/write in C++?
body: <p>How do you copy one stream to another using dedicated read/write threads in C++?</p>
  
  <p>Let's say I have these methods (not real, but to illustrate the point) to read/write data from. These read/write functions could represent anything (network/file/USB/serial/etc).</p>
  
  <pre><code>// returns the number of bytes read
  void read(char* buffer, int bufferSize, int* bytesRead);
  // returns the number of bytes written
  void write(char* buffer, int bufferSize, int* bytesWritten);
  </code></pre>
  
  <p>The solution should also be portable.</p>
  
  <p><strong>NOTE</strong>: I am aware that Windows has a <code>FILE_FLAG_OVERLAPPED</code> feature, but this assumes that the read/write is file IO. Remember, these read/write methods could represent anything.</p>