Home > Backend Development > C++ > body text

Why are Multiple Threads Created in Windows 10 C Applications?

DDD
Release: 2024-10-27 00:46:30
Original
229 people have browsed it

Why are Multiple Threads Created in Windows 10 C   Applications?

Windows 10's Mysterious Thread Creation in C Applications

In this inquiry, a perplexing observation was made regarding the unexpected creation of additional threads when running a simple C program in Windows 10. Using Visual Studio 2015, a new Console application was created with the following code:

<code class="cpp">int main() {
    return 0;
}</code>
Copy after login

Upon setting a breakpoint at the return statement and running the program in the debugger, the program exhibited only one thread on Windows 7. However, on Windows 10, a surprising number of five threads were present: the main thread and four additional "worker threads" waiting on a synchronization object.

Unveiling the Thread Origin

The question posed was: "Who's starting up these extra threads?" To investigate, it was suggested to access the "Debug > Windows > Threads" window and enable the Microsoft Symbol Server for improved visibility. This revealed that the additional threads were identified as "ntdll.dll!TppWorkerThread."

The Role of DLL Loading

Setting a breakpoint at the TppWorkerThread() entrypoint yielded a valuable stack trace that provided insights into the origin of these threads. It was discovered that the Windows 10 loader was utilizing the thread pool to load DLLs. This behavior was absent in Windows 7, indicating a significant change in Windows 10's initialization process.

Concurrent Initialization for Faster Startup

By leveraging multiple cores, Windows 10 effectively speeds up the initialization of the application by executing both the main thread and the DLL loading tasks concurrently. This behavior enhances the overall initialization performance and showcases the advantages of Windows 10's advanced resource management capabilities.

The above is the detailed content of Why are Multiple Threads Created in Windows 10 C Applications?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!