当前位置: 代码迷 >> 综合 >> pthread_create()和pthread_atfork()函数使用时应注意的问题
  详细解决方案

pthread_create()和pthread_atfork()函数使用时应注意的问题

热度:26   发布时间:2024-01-14 00:31:48.0

pthread_create()和pthread_atfork()函数使用时应注意的问题

由于 pthread 库不是 Linux 系统默认的库,连接时需要使用库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,在编译中要加 -lpthread参数。
例如:在加了头文件#include <pthread.h>之后执行 pthread.c文件,需要使用如下命令:
    gcc 【-o pthread】 -lpthread pthread.c
    这种情况类似于<math.h>的使用,需在编译时加 -m 参数。