您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Linux C程序中获取pthread的线程ID?

如何在Linux C程序中获取pthread的线程ID?

pthread_self() 函数将给出当前线程的线程ID。

pthread_t pthread_self(void);

pthread_self()函数返回调用线程的Pthread句柄。pthread_self()函数不会返回调用线程的整数线程。您必须使用pthread_getthreadid_np()返回该线程的整数标识符。

注意:

pthread_id_np_t   tid;
tid = pthread_getthreadid_np();

比这些调用快得多,但是提供了相同的行为。

pthread_id_np_t   tid;
pthread_t         self;
self = pthread_self();
pthread_getunique_np(&self, &tid);
其他 2022/1/1 18:14:11 有834人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶