How to Join a Thread in C++? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In C++, a thread is a basic element of multithreading that represents the smallest sequence of instructions that can be executed independently by the CPU. In this article, we will discuss how to join a thread in C++. How to Join a Thread in C++?Joining a thread is a means to wait for the thread to complete its execution before moving to the next part of the program. We can join the thread using the std::thread::join() function. It is a member function that makes sure that the execution of the thread is complete before moving on to the next statement after the join() function call. C++ Program to Join a Thread C++ // C++ Program to illustrate how to join a thread #include <iostream> #include <thread> using namespace std; // Define a function to be executed by the thread void myFunction() { cout << "Thread started" << endl; // Do some work cout << "Thread finished" << endl; } int main() { // Print a message indicating the start of the main // thread cout << "Main thread started" << endl; // Create a new thread and associate it with the // function myFunction thread myThread(myFunction); // Wait for the created thread (myThread) to finish // execution myThread.join(); cout << "Main thread finished" << endl; return 0; } Output:Main thread startedThread startedThread finishedMain thread finished Create Quiz Comment R rohitdubey214 Follow 0 Improve R rohitdubey214 Follow 0 Improve Article Tags : C++ Programs C++ cpp-multithreading CPP Examples Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like