boost怎么获取线程id
答案:1 悬赏:20 手机版
解决时间 2021-03-02 03:55
- 提问者网友:却不属于对方
- 2021-03-01 10:24
boost怎么获取线程id
最佳答案
- 五星知识达人网友:拾荒鲤
- 2021-03-01 10:41
boost如何获取线程id?
已经创建了一个线程对象,为boost::thread* pthread = new boost::thread(...);
我想获取这个线程对象的id,
就像win32的函数GetCurrentThreadId返回值一样。
阅读文档发现pthread->get_id()能够返回一个boost::thread::id类型的对象
但是这个对象没有办法将其中的thread id打印出来,有谁知道该怎么办吗?
调试窗口能够看到这个threadid的值,但是无法转为int值
native_handle()方法可以
boost::thread class has members native_handle_type and native_handle providing access to the underlying native handle.
This native handle can be used to change for example the scheduling.
11
XML to PDF by RenderX XEP XSL-FO Formatter, visit us at
Thread
In general, it is not safe to use this handle with operations that can conflict with the ones provided by Boost.Thread. An example of
bad usage could be detaching a thread directly as it will not change the internals of the boost::thread instance, so for example
the joinable function will continue to return true, while the native thread is no more joinable.
thread t(fct);
thread::native_handle_type hnd=t.native_handle();
pthread_detach(hnd);
assert(t.joinable());
已经创建了一个线程对象,为boost::thread* pthread = new boost::thread(...);
我想获取这个线程对象的id,
就像win32的函数GetCurrentThreadId返回值一样。
阅读文档发现pthread->get_id()能够返回一个boost::thread::id类型的对象
但是这个对象没有办法将其中的thread id打印出来,有谁知道该怎么办吗?
调试窗口能够看到这个threadid的值,但是无法转为int值
native_handle()方法可以
boost::thread class has members native_handle_type and native_handle providing access to the underlying native handle.
This native handle can be used to change for example the scheduling.
11
XML to PDF by RenderX XEP XSL-FO Formatter, visit us at
Thread
In general, it is not safe to use this handle with operations that can conflict with the ones provided by Boost.Thread. An example of
bad usage could be detaching a thread directly as it will not change the internals of the boost::thread instance, so for example
the joinable function will continue to return true, while the native thread is no more joinable.
thread t(fct);
thread::native_handle_type hnd=t.native_handle();
pthread_detach(hnd);
assert(t.joinable());
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯