c++ - 为什么进程会在 RtlExitUserProcess/LdrpDrainWorkQueue 中挂起?

标签 c++ windows multithreading process

为了调试锁定文件问题,我们从 .NET 进程调用 SysInternal 的 Handle64.exe 4.11(通过具有异步输出重定向的 Process.Start)。调用进程在 Process.WaitForExit 挂起,因为 Handle64 进程没有退出(超过两个小时)。

我们转储了相应的 Handle64 进程,并在 Visual Studio 2017 调试器中对其进行了检查。它显示了两个线程(“主线程”和“ntdll.dll!TppWorkerThread”)。

主线程的调用栈:

ntdll.dll!NtWaitForSingleObject ()  Unknown
ntdll.dll!LdrpDrainWorkQueue()  Unknown
ntdll.dll!RtlExitUserProcess()  Unknown
kernel32.dll!ExitProcessImplementation  ()  Unknown
handle64.exe!000000014000664c() Unknown
handle64.exe!00000001400082a5() Unknown
kernel32.dll!BaseThreadInitThunk    ()  Unknown
ntdll.dll!RtlUserThreadStart    ()  Unknown

工作线程的调用栈:

ntdll.dll!NtWaitForSingleObject()   Unknown
ntdll.dll!LdrpDrainWorkQueue()  Unknown
ntdll.dll!LdrpInitializeThread()    Unknown
ntdll.dll!_LdrpInitialize() Unknown
ntdll.dll!LdrInitializeThunk()  Unknown

我的问题是:为什么进程会在 LdrpDrainWorkQueue 中挂起?来自 https://stackoverflow.com/a/42789684/62838 ,我知道这是 Windows 10 并行加载器在工作,但为什么它会在退出进程时卡住?这可能是由我们如何从另一个进程调用 Handle64 引起的吗?即,我们是在做错什么,还是这是 Handle64 中的错误?

最佳答案

你等了多久?

根据 this analysis ,

The worker thread idle timeout is set to 30 seconds. Programs which execute in less than 30 seconds will appear to hang due to ntdll!TppWorkerThread waiting for the idle timeout before the process terminates.

我建议尝试设置那篇文章中指定的注册表项以禁用并行加载程序,看看这是否解决了问题。

Parent Key: HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\handle64.exe
Value Name: MaxLoaderThreads
Type: DWORD
Value: 1 to disable

关于c++ - 为什么进程会在 RtlExitUserProcess/LdrpDrainWorkQueue 中挂起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52649476/

相关文章:

windows - 什么是 Windows 事件日志记录

java - Spring的Singleton作用域bean在Web应用程序中的表现如何?

c# - 如何在不违背其目的的情况下为 ParallelQuery 编写 Map-Method?

c++ - 由定义保护的文档功能?

c++ - 如何在 C++ 中获取当前 CPU 和 RAM 使用情况?

windows - 如何在目录路径中多次返回?

python - mod_wsgi 不适用于 WAMP

c - 线程安全队列的问题表现为 IDE 控制台中没有输出

c++ - 在 C++ 中初始化 const 字符串的静态 const 数组

c++ - 用以下方式总结数组元素的有效方法是什么?