简体   繁体   中英

How to access the default thread pool in C++ windows 10 application?

According to this SO Question: "Why does Windows 10 start extra threads in my program?" and Hans Passant answer: Windows 10 start a thread pool for each and every C++ process on Windows 10 (at least when compiled in c++ in VS2013+).

According to Microsoft documentation "Thread Pools" and "Thread Pool API (2018-05-30)" , I cannot find the way to join the default process thread pool.

Can I join the default process thread pool and how? ... or do I have to create a new one?

This is a list of few drawbacks I could see of having more than one thread pool per process:

  • More threads created that could have been avoided
  • More sleeping threads
  • More memory taken for additional threads and the manager itself
  • Less efficent thread management algorithm due to possible concurrency between thread pool.

If I have to create new thread pool instead of joining/using one global thread pool per process, does it remove the advantage of having one and only one thread pool per process? Why can't we verify if there is an already created thread pool and use it directly? Why not just being able to join the main process thead pool? Wouldn't be better to have only one thread pool like in C#?

Side note: I'm working on a math algorithm that calculate long enough to be multi-threaded. Also, it is part of a libary into a 3rd party DLL. Being able to join an already created thread pool would have appears more logical to me than created a new one and perhaps interfere with the customer main process threads and another potential thread pool.

After I got a good answer and great informations from Raymon Chen, I discovered this article that I like to share because it helped me a lot to better understand: Top 20 C++ multithreading mistakes and how to avoid them

std::async uses the default thread pool on Windows, so you might like to use that.

More details here and here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM