Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::thread::hardware_concurrency

      From cppreference.com
      <cpp‎ |thread‎ |thread

      [edit template]
       
       
      Concurrency support library
      Threads
      (C++11)
      (C++20)
      this_thread namespace
      (C++11)
      (C++11)
      (C++11)
      Cooperative cancellation
      Mutual exclusion
      Generic lock management
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      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
       
       
      staticunsignedint hardware_concurrency()noexcept;
      (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, returns0.

      [edit]Example

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

      [8]ページ先頭

      ©2009-2025 Movatter.jp