Namespaces
Variants

std::jthread:: hardware_concurrency

From cppreference.net

Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
static unsigned int hardware_concurrency ( ) noexcept ;
(seit C++20)

Gibt die Anzahl der nebenläufigen Threads zurück, die von der Implementierung unterstützt werden. Der Wert sollte nur als Hinweis betrachtet werden.

Inhaltsverzeichnis

Parameter

(keine)

Rückgabewert

Anzahl der gleichzeitig unterstützten Threads. Wenn der Wert nicht wohldefiniert oder nicht berechenbar ist, wird 0 zurückgegeben.

Beispiel

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

Mögliche Ausgabe:

4 concurrent threads are supported.

Siehe auch

Mindestabstand zur Vermeidung von False Sharing
Maximalabstand zur Förderung von True Sharing
(Konstante)