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 ;
(C++20부터)

구현에서 지원하는 동시 스레드 수를 반환합니다. 이 값은 단지 힌트로만 간주되어야 합니다.

목차

매개변수

(없음)

반환값

지원되는 동시 스레드 수. 값이 명확하게 정의되지 않거나 계산할 수 없는 경우 0 을 반환합니다.

예제

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

가능한 출력:

4 concurrent threads are supported.

참고 항목

거짓 공유(false sharing)를 방지하기 위한 최소 오프셋
진짜 공유(true sharing)를 촉진하기 위한 최대 오프셋
(상수)