I want to be able to identify threads by a simple id when logging so that it is easy to trace the execution of a single thread. With windows using the API GetCurrentThreadId() can achieve what I want. In boost::thread there is a method get_id() but this doesn't represent an integral value like an integer. This object does have a thread_data member which contains an id which seems to be what I want but the data member is private so can't be accessed.
What is the boost way to access the thread id for display or identification purposes?
Boost includes an
operator<<(std::ostream&, const boost::thread::id&)overload that can be used to write a thread id to a stream (actually, the overload is a template and will work with any specialization ofstd::basic_ostream, not juststd::ostream).The result of printing the id is likely platform-specific, since different platforms may use different internal representations for thread identifiers.