[英]In a multithreaded c++ program using boost, is there any way to get a pointer to the current thread?
我需要知道当前线程的身份,以跟踪哪些线程正在对共享数据结构发出某些请求。
You can use boost::this_thread::get_id()
to get a boost::thread::id
representing the thread. 您可以使用
boost::this_thread::get_id()
获得代表线程的boost::thread::id
。
I don't think you can get a pointer to a boost::thread
object, because the thread doesn't necessarily have one attached. 我认为您无法获得指向
boost::thread
对象的指针,因为该线程不一定要附加一个。 And it cannot make one because it might have one attached. 它不能制造一个,因为它可能有一个附属。
没办法,但是您可以支持成对的hashmap:thread-id线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.