简体   繁体   English

在使用boost的多线程c ++程序中,是否有任何方法可以获取指向当前线程的指针?

[英]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.

相关问题 多线程C ++程序未使用向量并行运行 <thread> 和.join() - Multithreaded C++ Program Not Running In Parallel Using vector<thread> and .join() 使用Boost :: Python获取指向Python实例的c ++指针 - Get a c++ pointer to a Python instance using Boost::Python C ++多线程指针指向的指针 - C++ multithreaded pointer to pointer to pointer 使用 C++ 和 Boost 获取当前时间(以毫秒为单位) - Get current time in milliseconds using C++ and Boost 这个简单的c ++程序是多线程的吗? - Is this simple c++ program multithreaded? C ++-有什么方法可以获取当前的执行行 - C++ - is there any way to get the current executing line 使用boost :: thread将c ++对象从一个线程传递到另一个线程的正确方法是什么? - What is the proper way to pass a c++ object from one thread to another using boost::thread? C ++ Boost线程glibc检测到无效的指针 - c++ boost thread glibc detected invalid pointer 使用Boost Thread的C ++链接器错误 - C++ linker error using Boost Thread 使用websocketpp库在多线程程序中为endpoint.listen()创建单独的增强线程 - Creating a separate boost thread for endpoint.listen() in a multithreaded program using websocketpp library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM