I have a main thread which do some not-so-heavy-heavy work and also I'm creating worker threads which do very-heavy work. All documentation and examples shows how to create a number of hardware threads equal to std::thread::hardware_concurrency()
. But since main thread already existed the number of threads becomes std::thread::hardware_concurrency() + 1
. For example:
- my machine supports 2 hardware threads.
- in main thread I'm creating this 2 threads and the total number of threads becomes 3.
- a core with the main thread do it's job plus (probably) the worker job.
Of course I don't want this because UI (which is done in main thread) becomes not responsive due to latency. What will happen if I create std::thread::hardware_concurrency() - 1
thread? Will it guarantee that the main thread and only main thread is running on single core? How can I check it?
P.S.: I'm using some sort of pool - I start threads on the program start and stop on exit. During the execution all worker threads run infinite while
loop.
Aucun commentaire:
Enregistrer un commentaire