|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <thread> | ||
std::thread::id get_id()noexcept; | (since C++11) | |
Returns theid of the current thread.
Contents |
(none)
id of the current thread.
#include <chrono>#include <iostream>#include <syncstream>#include <thread>usingnamespace std::chrono_literals; void foo(){std::thread::id this_id= std::this_thread::get_id(); std::osyncstream(std::cout)<<"thread "<< this_id<<" sleeping...\n"; std::this_thread::sleep_for(500ms);} int main(){std::jthread t1{foo};std::jthread t2{foo};}
Possible output:
thread 140113018054400 sleeping...thread 140113009661696 sleeping...
| returns theid of the thread (public member function of std::thread)[edit] | |
C documentation forthrd_current | |