std::thread..._concurrency(3)

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

πŸ’– NAME πŸ’–

okay so bestie, this is the C++ Standard Library page for std::thread::hardware_concurrency β€” and yes, the NAME line is literally std::thread::hardware_concurrency - std::thread::hardware_concurrency, because apparently we’re doing the whole β€œsay it twice, it’s iconic” thing. The man page vibe is std::thread..._concurrency(3), iykyk. πŸŽ€


✨ Synopsis ✨

static unsigned int hardware_concurrency() noexcept;  (since C++11)

This cutie returns the number of concurrent threads supported by the implementation. The value should be considered only a hint β€” like, it’s giving β€œestimate,” not β€œsacred prophecy,” bestie. πŸ¦‹


🫢 Parameters 🫢

(none) β€” literally no parameters. Zero. Zilch. Not a single argument to hand over. πŸ’…


🌸 Return value 🌸

It returns the number of concurrent threads supported. And if the value is not well defined or not computable, it returns 0. That’s the whole return-value story, no cap. 😭


πŸ”₯ Example πŸ”₯

// Run this code

#include <iostream>
#include <thread>

int main()
{
    unsigned int n = std::thread::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. It’s tagged (C++17) (constant).
  • hardware_constructive_interference_size β€” max offset to promote true sharing. Also tagged (C++17) (constant).

mwah πŸ’‹ β€” this little manpage moment came from cppreference.com, dated 2024.06.10. periodt. 🌈

πŸ“¦ where this page comes from