Thread get_id() function in C++

In this tutorial, we will be discussing a program to understand thread get_id() function in C++.

Thread get_id() function verifies the current state of the process and then returns the id for the current thread in execution. This function doesn’t take any parameters.


#include <chrono>
#include <iostream>
#include <thread>
using namespace std;
//creating thread
void sleepThread(){
int main(){
   thread thread1(sleepThread);
   thread thread2(sleepThread);
   thread::id t1_id = thread1.get_id();
   thread::id t2_id = thread2.get_id();
   cout << "ID associated with thread1= " << t1_id << endl;
   cout << "ID associated with thread2= " << t2_id << endl;
   return 0;


ID associated with thread1= 135456142132844
ID associated with thread2= 135121414221716

Updated on: 12-Mar-2020


Kickstart Your Career

Get certified by completing the course

Get Started