C++ gettid() was not declared in this scope

二次信任 提交于 2019-12-02 20:57:06
Glenn Maynard

This is a silly glibc bug. Work around it like this:

#include <unistd.h>
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)

The man page you refer to can be read online here. It clearly states:

Note: There is no glibc wrapper for this system call; see NOTES.

and

NOTES

Glibc does not provide a wrapper for this system call; call it using syscall(2).

The thread ID returned by this call is not the same thing as a POSIX thread ID (i.e., the opaque value returned by pthread_self(3)).

So you can't. The only way to use this function is through the syscall.

But you probably shouldn't anyway. You can use pthread_self() (and compare using pthread_equal(t1, t2)) instead. It's possible that boost::thread has its own equivalent too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!