Namespaces
Variants
Actions

std::jthread::hardware_concurrency

From cppreference.com
< cpp‎ | thread‎ | jthread
 
 
Concurrency support library
(C++11)
(C++20)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++17)
(C++11)
(C++11)
(C++17)
(C++11)
(C++14)
(C++11)
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++26)
(C++26)
(C++26)
(C++26)
(C++11)
(C++20)
(C++11)
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
(C++11)
(C++11)(deprecated in C++26)
 
 
static unsigned int hardware_concurrency() noexcept;
(since C++20)

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

[edit] Parameters

(none)

[edit] Return value

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

[edit] Example

Run this code
#include <iostream>
#include <thread>
 
int main()
{
 unsigned int n = std::jthread::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) [edit]
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/thread/jthread/hardware_concurrency&oldid=120718"

AltStyle によって変換されたページ (->オリジナル) /