std::thread::hardware_concurrency - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::thread::hardware_concurrency

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

static unsigned hardware_concurrency(); |  | (since C++11)

Returns the number of concurrent threads supported by the implementation. The value should be considered only a hint.

### [edit] Parameters

(none)

### [edit] Return value

number of concurrent threads supported. If the value is not well defined or not computable, returns ​0​.

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] 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.

### [edit] See also

hardware_destructive_interference_sizehardware_constructive_interference_size (C++17) | min offset to avoid false sharing max offset to promote true sharing (constant) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/thread/thread/hardware_concurrency&oldid=91735"
Category:

- unconditionally noexcept

Hidden categories:

- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template