ubuntu 找不到 "gettid" 函数?

ubuntu cannot find "gettid" function?

我有一个非常小的程序来测试线程相关的东西:

#include<unistd.h>
#include<sys/types.h>
#include<stdio.h>
int main()
{
    pid_t pid=getpid();
    pid_t tid=gettid();
    printf("%d,%d\n",pid,tid);
    return 0;
}

在 vim 编辑器中,我专注于 'gettid' 和 Shift-K,gettid 的手册页说它在 sys/types 中。没问题,编译的时候报错:

g++ mythread.cpp 
mythread.cpp: In function ‘int main()’:
mythread.cpp:7:22: error: ‘gettid’ was not declared in this scope
     pid_t tid=gettid();
                  ^

我在 ubuntu1604 上使用新的 gcc 版本。如何解决?

使用:pid_t tid = 系统调用(SYS_gettid); 因为这不能直接调用。