Windows 10's Thread Pool in Action
Why does Windows 10 introduce additional threads in an ostensibly simple C program? This question arises when comparing the behavior of such a program on Windows 7 and Windows 10. While Windows 7 shows only one thread in the debugger, Windows 10 displays five threads, including four "worker threads."
The key to understanding this phenomenon lies in the role of the loader, ntdll.dll, on Windows 10. By setting a breakpoint on the TppWorkerThread() function, the entry point for thread-pool threads, we can capture the stack trace of the first threadpool thread being created.
The stack trace reveals that the loader is utilizing the threadpool to load DLLs on Windows 10. This concurrency allows Windows 10 to take advantage of multiple cores, resulting in faster process initialization.
Therefore, the additional threads seen in a simple C program on Windows 10 are a byproduct of the loader's optimization techniques. This behavior is intended to enhance performance and can be attributed to Windows 10's advancements in resource management.
The above is the detailed content of Why Are There Extra Threads in Simple C Programs on Windows 10?. For more information, please follow other related articles on the PHP Chinese website!