【发布时间】:2017-05-23 20:31:39
【问题描述】:
我有一个非常小的程序来测试线程相关的东西:
#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 版本。如何解决?
【问题讨论】:
标签: c++ linux compilation pthreads posix