InterviewSolution
| 1. |
How Can I Avoid "oversubscription" In C++11 When Working With Multiple Threads? |
|
Answer» C++11 provides a way to get a HINT at the NUMBER of threads that can be RUN in parallel from an APPLICATION – which most of the time COINCIDES with the number of logical cores. unsigned int n = std::thread::hardware_concurrency(); On my system with 12 logical cores, it returns 12. This means that I should not attempt to fork more than 12 threads in my application. Note that this is VC++ – other C++ compiler implementations might give different results C++11 provides a way to get a hint at the number of threads that can be run in parallel from an application – which most of the time coincides with the number of logical cores. unsigned int n = std::thread::hardware_concurrency(); On my system with 12 logical cores, it returns 12. This means that I should not attempt to fork more than 12 threads in my application. Note that this is VC++ – other C++ compiler implementations might give different results |
|