Boost Thread ID Invalid
i have bunch of question regarding to boost thread ?
-
开发者_Python百科
- How to initialize the boost thread ID with the thread constructor?
- Why the thread id becomes invalid after called join() function ?
- As usual, a class member function is copy to thread internal storage in order to execute the member function but i found out that someone just encapsulates the boost thread in a class. What is the purposes for this ?
On the other hands, do we allow to inherit the boost thread ? Please help.
Thanks.
- You can get the ID from a
boost::thread
object by calling it'sget_id()
member function:
boost::thread t(do_something);
boost::thread::id tid=t.get_id();
You can get the ID of the current thread by calling boost::this_thread::get_id()
.
Thread ID values remain valid after a thread exits, unlike the thread IDs for some OS thread libraries.
If you pass in the address of a member function, and the address of an object then you can run a member function on that object on a new thread. You can therefore start threads in a member function, and pass
this
as the object pointer. This allows the new thread to share data via the data members of the class instance.You can derive from
boost::thread
but it wouldn't really get you anywhere as there are no virtual functions.
Answer to 2:because calling join waits until thread gets terminated, and becomes invalid.
精彩评论