To retrieve the id of the current a specific function in the boost::this_thread, aptly named get_id() is made available.
The id of a boost thread is not yet, or no more, associated with a low level thread, its id assumes a dummy value "not-any-thread".
In this short example we dump the id of the current thread, then the one of another active thread, and finally the id of the same boost thread object, after the underlying system thread has been terminated:
#include <iostream>
#include <boost/thread.hpp>
namespace
{
class Callable
{
// as defined in a previous post
};
}
void t04()
{
std::cout << "Checking thread IDs" << std::endl;
std::cout << "Current thread id: " << boost::this_thread::get_id() << std::endl;
boost::thread t(Callable(5));
std::cout << "Other thread id: " << t.get_id() << std::endl;
t.join();
std::cout << "Other thread id: " << t.get_id() << std::endl;
std::cout << "Done thread id testing" << std::endl;
}
No comments:
Post a Comment