Thread hardware_concurrency() function in C++ Last Updated : 30 Oct, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report Thread::hardware_concurrency is an in-built function in C++ std::thread. It is an observer function which means it observes a state and then returns the corresponding output. This function returns the number of concurrent threads supported by the available hardware implementation. This value might not always be accurate. Syntax: thread::hardware_concurrency() Parameters: This function does not accept any parameters. Return Value: It returns a non-negative integer denoting the number of concurrent threads supported by the system. If the value is either not computable or not well defined it returns 0. Below program demonstrate the use of std::thread::joinable() Note: On the online IDE this program will show error. To compile this, use the flag “-pthread” on g++ compilers compilation with the help of command “g++ –std=c++14 -pthread file.cpp”. CPP // C++ program to demonstrate the use of // std::thread::hardware_concurrency() #include <chrono> #include <iostream> #include <thread> using namespace std; int main() { unsigned int con_threads; // calculating number of concurrent threads // supported in the hardware implementation con_threads = thread::hardware_concurrency(); cout << "Number of concurrent threads supported are: " << con_threads << endl; return 0; } Possible Output Number of concurrent threads supported are: 4 Comment More infoAdvertise with us Next Article Thread hardware_concurrency() function in C++ K Kushagra7744 Follow Improve Article Tags : C++ STL cpp-multithreading Practice Tags : CPPSTL Similar Reads Concurrency in C++ Concurrency refers to the ability to process multiple tasks or threads at the same time. It is used to improve the program's performance and response time. In this article, we will discuss how concurrency is achieved in C++ and what are its benefits. Concurrency in C++In C++, the support for concurr 5 min read Thread Synchronization in C++ In C++ multithreading, synchronization between multiple threads is necessary for the smooth, predictable, and reliable execution of the program. It allows the multiple threads to work together in conjunction by having a proper way of communication between them. If we do not synchronize the threads w 7 min read Sleep Function in C++ C++ provides the functionality of delay or inactive state of the program with the help of the operating system for a specific period of time. Other CPU operations will function adequately but the sleep() function in C++ will sleep the present executable for the specified time by the thread.The sleep 3 min read Sharing a queue among three threads Share a queue among three threads A, B, C as per given norms : Thread A generates random integers and pushes them into a shared queue.Threads B and C compete with each other to grab an integer from the queue.The threads B and C compute the sum of integers that they have grabbed from the queue.Compar 5 min read thread_local Storage in C++ 11 Thread local storage (TLS) is a feature introduced in C++ 11 that allows each thread in a multi-threaded program to have its own separate instance of a variable. In simple words, we can say that each thread can have its own independent instance of a variable. Each thread can access and modify its ow 3 min read Like