Thread::joinable 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 and checks whether the thread object is joinable or not.
A thread object is said to be joinable if it identifies/represent an active thread of execution.
A thread is not joinable if:
- It was default-constructed
- If either of its member join or detach has been called
- It has been moved elsewhere
Parameters: This function does not accepts any parameters.
Return Value: It is a boolean type function and returns true when the thread object is
joinable. It returns false if the thread object is not joinable.
The following 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”.
t1 joinable when default created? NO t1 joinable when put to sleep? YES t1 joinable after join is called? NO
Note: The third output will appear 1 sec later because the thread was put to sleep for 1 minute.
- Thread get_id() function in C++
- Thread hardware_concurrency() function in C++
- Print numbers in sequence using thread synchronization
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- div() function in C++
- fma() function in C++
- log() function in C++
- exp() function C++
- strrchr() function in C/C++
- strcspn() function in C/C++
- unordered_map end( ) function in C++ STL
- iswxdigit() function in C/C++
- towlower() function in C/C++
- iswspace() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.