std::thread::hardware_concurrency

From cppreference.com
< cpp‎ | thread‎ | thread
 
 
Thread support library
Threads
(C++11)
this_thread namespace
(C++11)
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
(C++11)
(C++17)
Generic lock management
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
 
std::thread
Member classes
Member functions
Observers
thread::hardware_concurrency
Operations
Non-member functions
 
static unsigned hardware_concurrency();
(since C++11)

Returns the number of concurrent threads supported by the implementation. The value should be considered only a hint.

Contents

[edit] Parameters

(none)

[edit] Return value

number of concurrent threads supported. If the value is not well defined or not computable, returns 0.

[edit] Exceptions

noexcept specification:  
noexcept
  

[edit] Example

#include <iostream>
#include <thread>
 
int main() {
    unsigned int n = std::thread::hardware_concurrency();
    std::cout << n << " concurrent threads are supported.\n";
}

Possible output:

4 concurrent threads are supported.

[edit] See also

min offset to avoid false sharing
max offset to promote true sharing
(constant)