C++ Concurrency Sandbox
Loading...
Searching...
No Matches
check_processors.cpp
Go to the documentation of this file.
1
/**
2
* @file check_processors.cpp
3
* @brief Utility to determine the optimal number of threads for the host system.
4
* * This program queries the hardware to find the number of supported concurrent threads.
5
* This value is critical for avoiding over-subscription in Thread Pools.
6
*/
7
8
#include <iostream>
9
#include <thread>
10
11
/**
12
* @brief Main entry point.
13
* @return 0 on success.
14
*/
15
int
main
() {
16
/**
17
* @brief The number of concurrent threads supported by the implementation.
18
* * The value should be considered a hint. If the value is not computable or well defined,
19
* this function returns 0.
20
*/
21
unsigned
int
n_threads = std::thread::hardware_concurrency();
22
23
std::cout <<
"--- Hardware Concurrency Check ---"
<< std::endl;
24
if
(n_threads == 0) {
25
std::cout <<
"Hardware concurrency not detectable. Defaulting to fallback."
<< std::endl;
26
}
else
{
27
std::cout <<
"Detected "
<< n_threads <<
" concurrent threads supported by hardware."
<< std::endl;
28
}
29
30
return
0;
31
}
main
int main()
Main entry point.
Definition
check_processors.cpp:15
Hardware-Cores-Check
check_processors.cpp
Generated by
1.9.8