http://bugs.winehq.org/show_bug.cgi?id=2127
------- Additional Comments From david.guembel@gmx.de 2005-03-10 08:52 ------- When removing the critical section, the problem still doesn't appear, not on uniprocessor, not on SMP, and neither when running several instances of the test program.
However, the application that causes the problem for me does not only do 1. CreateFile, 2. WriteFile, 3. CloseHandle (like the test code above does), but 1. CreateFile, 2. ReadFile, 3. CloseHandle, 4. CreateFile, 5. WriteFile, 6. CloseHandle. I.e., it opens the file for reading, reads, closes the file, opens it for writing, writes, closes the file. That still causes errors, and as you suspected, the WriteFile gives me a 6 (= INVALID_HANDLE).
I noticed that if I open the file for reading (step 1.) using GENERIC_READ | GENERIC_WRITE, close it, then open it for writing (step 4.) using GENERIC_WRITE, there is no problem. However if I open it for reading with GENERIC_READ only, close it, and open it with GENERIC_WRITE for writing, the WriteFile gives me the INVALID_HANDLE after some time. Looks like your assumption about the race in the cache is correct, doesn't it?
Anything else you'd like to see tested?