title: Unable to read same file in parallel
body: <p>I am trying to read a logfile in two different applications at the same time. But <strong>CreateFile</strong> (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx</a>) with share-mode #FILE_SHARE_READ always fails on the second call with error-code 32: <strong>ERROR_SHARING_VIOLATION: - The process cannot access the file because it is being used by another process.</strong></p>
  
  <p>When the logfile is written in modes FILE_SHARE_WRITE or FILE_SHARE_READ | FILE_SHARE_WRITE the file can not be read by any of the two applications only when FILE_SHARE_READ is used for the writer-application and then it only works if the reader-applications use FILE_SHARE_WRITE or FILE_SHARE_READ | #FILE_SHARE_WRITE, not when using #FILE_SHARE_READ. Strange .... Any suggestions?</p>
  
  <p>Thank you very much.</p>
  
  <p>Amendment:</p>
  
  <pre><code>Writer-Application: CreateFile(file,GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0)
  Reader-Applications: CreateFile(file,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0)
  </code></pre>
  
  <p>Amendment 2:</p>
  
  <p>When using the calls from the first Amendment the 1st Reader-Application can successfully get the filehandle, but the 2nd Reader-Application will fail with ERROR_SHARING_VIOLATION.</p>
  
  <p><strong>Amendment 3: One pointed me to the solution!</strong></p>
  
  <p><strong>The problem was that I used logical Or instead of bitwise Or for the share-mode:
  FILE_SHARE_READ Or FILE_SHARE_WRITE = 1 Or 2 = 1, but it should be FILE_SHARE_READ | FILE_SHARE_WRITE = 1 | 2 = 3. So could not work as the Writer-Application required FILE_SHARE_WRITE.</strong></p>