开发者

Boost Thread ID Invalid

开发者 https://www.devze.com 2023-01-14 07:03 出处:网络
i have bunch of question regarding to boost thread ? 开发者_Python百科How to initialize the boost thread ID with the thread constructor?

i have bunch of question regarding to boost thread ?

    开发者_Python百科
  1. How to initialize the boost thread ID with the thread constructor?
  2. Why the thread id becomes invalid after called join() function ?
  3. 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.


  1. You can get the ID from a boost::thread object by calling it's get_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().

  1. Thread ID values remain valid after a thread exits, unlike the thread IDs for some OS thread libraries.

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消