VOOZH about

URL: https://www.geeksforgeeks.org/cpp/how-to-join-a-thread-in-cpp/

⇱ How to Join a Thread in C++? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Join a Thread in C++?

Last Updated : 23 Jul, 2025

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

Output:

Main thread started
Thread started
Thread finished
Main thread finished


Comment