为什么Windows 10在我的程序中启动额外的线程? [英] Why does Windows 10 start extra threads in my program?

查看:3142
本文介绍了为什么Windows 10在我的程序中启动额外的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2015中,在一个新的空的C ++项目中,为控制台应用程序构建以下内容:

With Visual Studio 2015, in a new, empty C++ project, build the following for Console application:

int main() {
    return 0;
}

在返回时设置断点并在调试器中启动程序。在Windows 7上,从断点开始,此程序只有一个线程。但在Windows 10上,它有五个(!)线程:主线程和四个工作线程等待同步对象。

Set a break point on the return and launch the program in the debugger. On Windows 7, as of the break point, this program has only one thread. But on Windows 10, it has five(!) threads: the main thread and four "worker threads" waiting on a synchronization object.

谁启动线程池或者我如何找到)?

Who's starting up the thread pool (or how do I find out)?

推荐答案

Crystal Ball说,Debug> Windows> Threads窗口以 ntdll.dll!TppWorkerThread 。一定要启用Microsoft符号服务器看到这个自己,使用工具>选项>调试>符号。

Crystal ball says that the Debug > Windows > Threads window shows these threads at ntdll.dll!TppWorkerThread. Be sure to enable the Microsoft Symbol Server to see this yourself, use Tools > Options > Debugging > Symbols.

这也发生在VS2013,所以它绝对不是由新的VS2015诊断功能,@ Adam的猜测不能正确。

This also happens in VS2013 so it is most definitely not caused by the new VS2015 diagnostic features, @Adam's guess cannot be correct.

TppWorkerThread()是线程池线程的入口点。当我在这个函数上使用Debug> New Breakpoint> Function Breakpoint设置断点时。我很幸运在第二个线程池线程开始执行时捕获第一个线程池线程的堆栈跟踪:

TppWorkerThread() is the entrypoint for a thread-pool thread. When I set a breakpoint with Debug > New Breakpoint > Function Breakpoint on this function. I got lucky to capture this stack trace for the 1st threadpool thread when the 2nd threadpool thread started executing:

    ntdll.dll!_NtOpenFile@24()  Unknown
    ntdll.dll!LdrpMapDllNtFileName()    Unknown
    ntdll.dll!LdrpMapDllSearchPath()    Unknown
    ntdll.dll!LdrpProcessWork() Unknown
    ntdll.dll!_LdrpWorkCallback@12()    Unknown
    ntdll.dll!TppWorkpExecuteCallback() Unknown
    ntdll.dll!TppWorkerThread() Unknown
    kernel32.dll!@BaseThreadInitThunk@12()  Unknown
    ntdll.dll!__RtlUserThreadStart()    Unknown
>   ntdll.dll!__RtlUserThreadStart@8()  Unknown

显然,装载器正在使用Windows 10上的线程池加载DLL。这肯定是新的:)此时,主线程也在加载器中执行,并发在工作。

Clearly the loader is using the threadpool on Windows 10 to load DLLs. That's certainly new :) At this point the main thread is also executing in the loader, concurrency at work.

因此Windows 10利用多个内核获得过程初始化更快。很多功能,而不是错误:)

So Windows 10 is taking advantage of multiple cores to get the process initialized faster. Very much a feature, not a bug :)

这篇关于为什么Windows 10在我的程序中启动额外的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆