
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 BoostThread 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=tnative_handle();
pthread_detach(hnd);
assert(tjoinable());
用AIP "GetWindowThreadProcessId" 版本 2
支持库 eAPI
支持库 spec程序集 窗口程序集1子程序 __启动窗口_创建完毕
局部变量 QQ窗口, 整数型
局部变量 进程, 进程信息
局部变量 iD, 整数型QQ窗口 = 取窗口句柄_ (0, “QQ2011”)
iD = 取窗口进程 (QQ窗口, 进程)'易语言精英 团队解答
调试输出 (iD)
版本 2
支持库 eAPIDLL命令 取窗口进程, 整数型, "user32", "GetWindowThreadProcessId", , 返回创建者的标志符。
参数 窗口句柄, 整数型, , 被查找窗口的句柄
参数 进程号, 进程信息, , 进程号的存放地址(变量地址)DLL命令 取窗口句柄_, 整数型, "user32", "FindWindowA"
参数 类名, 整数型
参数 标题, 文本型
以先用tasklist找出javamail的PID,然后找出netstat与上述PID对应的端口号
Process pro=RuntimegetRuntime()exec("cmdexe /c tasklist")
BufferedReader input = new BufferedReader(new InputStreamReader(processgetInputStream()));
String line = " ";
while ((line = inputreadLine()) != null)
{
//把读出的line取出javamail的PID,
}
获取netstat PID对应的端口号仿照上述即可
ThreadCurrentThread
获得的就是执行改方法的线程,你肯定是开了很多线程,线程有自己的线程ID,你可以通过打印的方式将线程ID打印出来看看是不是结束正确的。
我不明白你所表述的代码逻辑,但是ThreadCurrentThread
绝对得到的是执行该方法的线程。
以上就是关于boost怎么获取线程id全部的内容,包括:boost怎么获取线程id、易语言怎么获取指定窗口的进程ID和线程ID呢求助!在线等、各位兄台,如何获得自己程序的当前线程所占用的端口等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)