C++ Concurrency Sandbox
Loading...
Searching...
No Matches
check_processors.cpp File Reference

Utility to determine the optimal number of threads for the host system. More...

#include <iostream>
#include <thread>
Include dependency graph for check_processors.cpp:

Go to the source code of this file.

Functions

int main ()
 Main entry point.
 

Detailed Description

Utility to determine the optimal number of threads for the host system.

  • This program queries the hardware to find the number of supported concurrent threads. This value is critical for avoiding over-subscription in Thread Pools.

Definition in file check_processors.cpp.

Function Documentation

◆ main()

int main ( void  )

Main entry point.

Returns
0 on success.

The number of concurrent threads supported by the implementation.

  • The value should be considered a hint. If the value is not computable or well defined, this function returns 0.

Definition at line 15 of file check_processors.cpp.

15 {
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}