title: C++ console application not returning
body: <p>I am running a C++ console application from the command line. The application queries data from a database system using ODBC and dumps the data into a text file. Occasionally, and especially when running few at the same time, the application doesn't return back leaving the command prompt waiting. I can't even stop it using ctrl-C. I have to use End-Task from Task Manager or ProcMon. I use fprintf at every step in the code and write to a separate log file, and I see that the application reached the end and supposedly called <code>return 0</code>. When it doesn't hang, the application takes about 40 seconds to query and dump the data. When the application hangs, I see that the log file and data dump files are generated as expected. 
  I use ProcMon and I see that the thread is waiting for itself. I get this message: </p>
  
  <blockquote>
    <p>one or more threads of odbcsql.exe are in waiting status.</p>
  </blockquote>
  
  <p>This is the stack trace that I find through ProcMon:</p>
  
  <ul>
  <li>ntoskrnl.exe!KeSynchronizeExecution+0x2246</li>
  <li>ntoskrnl.exe!KeWaitForMultipleObjects+0x135e</li>
  <li>ntoskrnl.exe!KeWaitForMultipleObjects+0xdd9</li>
  <li>ntoskrnl.exe!KeWaitForSingleObject+0x373</li>
  <li>ntoskrnl.exe!KeStallWhileFrozen+0x1977</li>
  <li>ntoskrnl.exe!KeIsAttachedProcess+0x95d</li>
  <li>ntoskrnl.exe!KeWaitForMultipleObjects+0x152f</li>
  <li>ntoskrnl.exe!KeWaitForMultipleObjects+0xdd9</li>
  <li>ntoskrnl.exe!KeWaitForSingleObject+0x373</li>
  <li>ntoskrnl.exe!NtWaitForSingleObject+0xb2</li>
  <li>ntoskrnl.exe!setjmpex+0x34a3</li>
  <li>wow64cpu.dll!TurboDispatchJumpAddressEnd+0x598</li>
  <li>wow64cpu.dll!TurboDispatchJumpAddressEnd+0x3e4</li>
  <li>wow64.dll!Wow64LdrpInitialize+0x23a</li>
  <li>wow64.dll!Wow64LdrpInitialize+0x172</li>
  <li>ntdll.dll!LdrInitShimEngineDynamic+0x23d5</li>
  <li>ntdll.dll!memset+0xdd1e</li>
  <li>ntdll.dll!LdrInitializeThunk+0xe</li>
  <li>UMEngx86.dll+0x242f</li>
  <li>UMEngx86.dll+0x1ec5</li>
  <li>UMEngx86.dll!_RegQueryValueExW@24+0x1ba4</li>
  <li>UMEngx86.dll!_RegQueryValueExW@24+0x18b2</li>
  <li>UMEngx86.dll!_RegQueryValueExW@24+0x17f4</li>
  <li>ntdll.dll!RtlInitializeCriticalSection+0x10e</li>
  <li>ntdll.dll!RtlInitializeCriticalSection+0x88</li>
  <li>ntdll.dll!RtlReportSilentProcessExit+0x108</li>
  <li>ntdll.dll!RtlExitUserProcess+0x81</li>
  <li>odbcsql.exe+0x2f0c</li>
  <li>odbcsql.exe+0x3185</li>
  <li>ntdll.dll!RtlInitializeExceptionChain+0x8f</li>
  <li>ntdll.dll!RtlInitializeExceptionChain+0x5a</li>
  </ul>
  
  <p>Any ideas or suggestions?</p>
  
  <p>Thanks!</p>