Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy would fclose hang / deadlock? (Windows)
    text
    copied!<p>I have a directory change monitor process that reads updates from files within a set of directories. I have another process that performs small writes to a lot of files to those directories (test program). Figure about 100 directories with 10 files in each, and about 500 files being modified per second.</p> <p>After running for a while, the directory monitor process hangs on a call to <code>fclose()</code> in a method that is basically tailing the file. In this method, I <code>fopen()</code> the file, check that the handle is valid, do a few seeks and reads, and then call <code>fclose()</code>. These reads are all performed by the same thread in the process. After the hang, the thread never progresses.</p> <p>I couldn't find any good information on why <code>fclose()</code> might deadlock instead of returning some kind of error code. The documentation does mention <code>_fclose_nolock()</code>, but it doesn't seem to be available to me (Visual Studio 2003).</p> <p>The hang occurs for both debug and release builds. In a debug build, I can see that <code>fclose()</code> calls <code>_free_base()</code>, which hangs before returning. Some kind of call into kernel32.dll => ntdll.dll => KernelBase.dll => ntdll.dll is spinning. Here's the assembly from ntdll.dll that loops indefinitely:</p> <pre><code>77CEB83F cmp dword ptr [edi+4Ch],0 77CEB843 lea esi,[ebx-8] 77CEB846 je 77CEB85E 77CEB848 mov eax,dword ptr [edi+50h] 77CEB84B xor dword ptr [esi],eax 77CEB84D mov al,byte ptr [esi+2] 77CEB850 xor al,byte ptr [esi+1] 77CEB853 xor al,byte ptr [esi] 77CEB855 cmp byte ptr [esi+3],al 77CEB858 jne 77D19A0B 77CEB85E mov eax,200h 77CEB863 cmp word ptr [esi],ax 77CEB866 ja 77CEB815 77CEB868 cmp dword ptr [edi+4Ch],0 77CEB86C je 77CEB87E 77CEB86E mov al,byte ptr [esi+2] 77CEB871 xor al,byte ptr [esi+1] 77CEB874 xor al,byte ptr [esi] 77CEB876 mov byte ptr [esi+3],al 77CEB879 mov eax,dword ptr [edi+50h] 77CEB87C xor dword ptr [esi],eax 77CEB87E mov ebx,dword ptr [ebx+4] 77CEB881 lea eax,[edi+0C4h] 77CEB887 cmp ebx,eax 77CEB889 jne 77CEB83F </code></pre> <p>Any ideas what might be happening here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload