The C Standard Library
The C++ Standard Library
The C++ STL Library
C++ Programming Resources
Selected Reading
The C++ Standard Library
- C++ Library - <valarray>
- C++ Library - <utility>
- C++ Library - <typeinfo>
- C++ Library - <tuple>
- C++ Library - <thread>
- C++ Library - <string>
- C++ Library - <stdexcept>
- C++ Library - <regex>
- C++ Library - <numeric>
- C++ Library - <new>
- C++ Library - <memory>
- C++ Library - <locale>
- C++ Library - <limits>
- C++ Library - <functional>
- C++ Library - <exception>
- C++ Library - <complex>
- C++ Library - <atomic>
- C++ Library - <streambuf>
- C++ Library - <sstream>
- C++ Library - <ostream>
- C++ Library - <istream>
- C++ Library - <iostream>
- C++ Library - <iosfwd>
- C++ Library - <ios>
- C++ Library - <iomanip>
- C++ Library - <fstream>
- C++ Library - Home
The C++ STL Library
- C++ Library - <iterator>
- C++ Library - <algorithm>
- C++ Library - <vector>
- C++ Library - <unordered_set>
- C++ Library - <unordered_map>
- C++ Library - <stack>
- C++ Library - <set>
- C++ Library - <queue>
- C++ Library - <map>
- C++ Library - <list>
- C++ Library - <forward_list>
- C++ Library - <deque>
- C++ Library - <bitset>
- C++ Library - <array>
C++ Programming Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
C++ Library - <thread>
C++ Library - <thread>
Introduction
Thread is a sequence of instructions that can be executed concurrently with other such sequences in multithreading environments, while sharing a same address spac.
Member types
Sr.No. | Member type & description |
---|---|
1 | It is a thread id. |
2 | It is a native handle type. |
Member functions
Sr.No. | Member function & description |
---|---|
1 | It is used to construct thread. |
2 | It is used to destructor thread. |
3 | It is a move-assign thread. |
4 | It is used to get thread id. |
5 | It is used to check if joinable. |
6 | It is used to join thread. |
7 | It is used to detach thread. |
8 | It is used to swap threads. |
9 | It is used to get native handle. |
10 | It is used to detect hardware concurrency. |
Non-member overloads
Sr.No. | Non-member overload & description |
---|---|
1 | It is used to swap threads. |
Example
In below example for std::thread.
#include <iostream> #include <thread> void foo() { std::cout << " foo is executing concurrently... "; } void bar(int x) { std::cout << " bar is executing concurrently... "; } int main() { std::thread first (foo); std::thread second (bar,0); std::cout << "main, foo and bar now execute concurrently... "; first.join(); second.join(); std::cout << "foo and bar completed. "; return 0; }
The output should be pke this −
main, foo and bar now execute concurrently... bar is executing concurrently... foo is executing concurrently... foo and bar completed.Advertisements