Thread::get_id() 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. This function returns the value of std::thread::id thus identifying the thread associated with *this.
Parameters: This function does not accept any parameters.
Return Value: This method returns a value of type std::thread::id identifying the thread associated with *this i.e. the thread which was used to call the get_id function is returned. The default constructed std::thread::id is returned when no such thread is identified.
Below examples demonstrates the use of std::thread::get_id() method:
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”.
ID associted with thread1= 139858743162624 ID associted with thread2= 139858734769920
- Thread joinable() function in C++
- Thread hardware_concurrency() function in C++
- Difference between User Level thread and Kernel Level thread
- Thread in Operating System
- Thread States in Operating Systems
- 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++
- log() function in C++
- exp() function C++
- div() function in C++
- fma() function in C++
- map rbegin() function in C++ STL
- map rend() function in C++ STL
- max() function for valarray in 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.