title: Synchronize I/O with calling thread?
body: <p>In <a href="http://msdn.microsoft.com/en-us/library/ms810438.aspx" rel="nofollow">this article</a>, section 'More Waiting...', when author talked about synchronize i/o with thread, the 1st example he gives is:</p>
  
  <pre><code>hFile = CreateFile(....,FILE_IO_OVERLAPPED,...);
  ReadFile(hFile,...)
  &lt; Do some computation.&gt;
  WaitForSingleObject(hFile,INFINITE);
  </code></pre>
  
  <p>I had the impression that both 'CreateFile' and 'ReadFile' are <strong>synchronous</strong> APIs, no? Why would a 'WaitForSingleObject' needed here? Wouldn't 'CreateFile' and 'ReadFile' block until the operation is over and then return?</p>
  
  <p>Then some more confusion coming when author talks about 'alertable waiting'. What is it, a thread state after WaitForSingleObjectEx()? then why author give:</p>
  
  <pre><code>while (WaitForSingleObject(hObject,TRUE)==WAIT_IO_COMPLETION);
  </code></pre>
  
  <p>as example instead of </p>
  
  <pre><code>while (WaitForSingleObjectEx(hObject,TRUE)==WAIT_IO_COMPLETION);
  </code></pre>
  
  <p>?</p>
  
  <p>and should 'ex' functions be together like:</p>
  
  <pre><code>hFile = CreateFile(....,FILE_IO_OVERLAPPED,...);
  ReadFileEx(hFile,...)
  &lt; Do some computation.&gt;
  while (WaitForSingleObjectEx(hObject,TRUE)==WAIT_IO_COMPLETION);
  </code></pre>
  
  <p>Any one can explain a little more?</p>
  
  <p>Thanks,</p>