std::jthrea...concurrency(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay bestie, welcome to the std::jthrea...concurrency(3) page from the C++ Standard Libary (yes, that's the spelling in the header, we're keeping it πŸ’…). This page is literally named std::jthread::hardware_concurrency - std::jthread::hardware_concurrency, and she's here to tell you how many concurrent threads your implementation says it can support. Iconic. ✨


πŸ¦‹ Synopsis πŸ¦‹

[[nodiscard]] static unsigned int hardware_concurrency() noexcept;

(since C++20) 🌸

She returns the number of concurrent threads supported by the implementation. Important vibe check: the value should be considered only a hint β€” not a promise, not a contract, just a hint, bestie. 🫢


🌸 Parameters 🌸

(none) β€” literally no parameters. Not a single one. Nada. πŸ’€


πŸŽ€ Return value πŸŽ€

Number of concurrent threads supported. If the value is not well defined or not computable, she returns 0. That's the whole deal. ✨


πŸ”₯ Example πŸ”₯

// Run this code β€” go off, run it:

#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.

πŸ‘‘ See also πŸ‘‘

  • hardware_destructive_interference_size β€” min offset to avoid false sharing
  • hardware_constructive_interference_size β€” max offset to promote true sharing
  • (C++17) β€” (constant)

okay that's the page, bestie πŸ’– sourced from http://cppreference.com, version/date 2024.06.10, manual std::jthrea...concurrency(3). periodt. 🫢✨

πŸ“¦ where this page comes from