pthread_exit函数以及Linux上编译链接问题
2016-12-05 22:35
477 查看
原型:void pthread_exit(void *retval)
用法:#include <pthread.h>
功能:使用函数pthread_exit退出线程,这是线程的主动行为;由于一个进程中的多个线程是共享数据段的,因此通常在线程退出之后,退出线程所占用的资源并不会随着线程的终止而得到释放,但是可以用pthread_join()函数(下篇博客中讲到)来同步并释放资源。
说明:retval:pthread_exit()调用线程的返回值,可由其他函数如pthread_join来检索获取。
备注:pthread库不是Linux系统默认的库,连接时需要使用静态库libpthread.a,所以在线程函数在编译时,需要连接库函数,如上图
gcc pthread_create.c -o pthread_create -lpthread
问题原因:
pthread
库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
问题解决:
在编译中要加 -lpthread参数
gcc thread.c -o thread -lpthread
thread.c为你些的源文件,不要忘了加上头文件#include<pthread.h>
用法:#include <pthread.h>
功能:使用函数pthread_exit退出线程,这是线程的主动行为;由于一个进程中的多个线程是共享数据段的,因此通常在线程退出之后,退出线程所占用的资源并不会随着线程的终止而得到释放,但是可以用pthread_join()函数(下篇博客中讲到)来同步并释放资源。
说明:retval:pthread_exit()调用线程的返回值,可由其他函数如pthread_join来检索获取。
备注:pthread库不是Linux系统默认的库,连接时需要使用静态库libpthread.a,所以在线程函数在编译时,需要连接库函数,如上图
gcc pthread_create.c -o pthread_create -lpthread
问题原因:
pthread
库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
问题解决:
在编译中要加 -lpthread参数
gcc thread.c -o thread -lpthread
thread.c为你些的源文件,不要忘了加上头文件#include<pthread.h>
相关文章推荐
- [链接] Linux下常见的~/.bashrc、/etc/profile、/etc/ld.so.config小科普以及caffe编译遇到的相关问题解决
- linux 里的eclips编译OpenGL链接不到相应库的问题
- Linux 编译报错 -- undefined reference to 问题解决方法 (具体'pthread_create'和opencv看文章最后两条)
- linux下g++ 编译时动态库和静态库的链接和头文件问题
- 解决Linux程序编译链接动态库版本的相关问题
- linux替换cudnn版本以及链接库碰到的问题
- linux 里的eclips编译OpenGL链接不到相应库的问题
- Linux编译问题:对‘pthread_create’未定义的引用
- 解决Linux下Qt编译出现"cannot find -lGL"以及无法安装libgl1-mesa-dev的问题
- linux下编译C++程序无法链接Mysql的问题
- linux编译时“ '对pthread_create' 未定义的引文"问题的解决方法
- 64位 linux 编译链接错库的问题
- Linux静态库和动态库编译链接问题
- 解决Linux下Qt编译出现"cannot find -lGL"以及无法安装libgl1-mesa-dev的问题
- Dev_c++下解决编译winsock和pthread 的链接问题C++&STL
- linux下生产者与消费者问题代码,以及编译c代码时error:undefined reference to sem_wait 解决方法之一
- linux下开发,解决cocos2d-x中编译出现的一个小问题, undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
- linux 与winscp /SecureCRT 链接关闭防火墙以及selinux问题
- Linux编译的时候由于链接库出现的各种问题
- linux下c++编程环境搭建,运行过程以及调试,内含C++头文件源文件编译过程链接