linux多线程函数,Linux多线程编程的基本的函数有哪些?

1线程创建 函数原型: #include

int pthread_create(pthread_t *restrict tidp,const pthread_attr_t *restrict attr, void *(*start_rtn)(void),void *restrict arg); 返回值:若是成功建立线程返回0,否则返回错误的编号 形式参数: pthread_t *restrict tidp 要创建的线程的线程id指针 const pthread_attr_t *restrict attr 创建线程时的线程属性 void* (start_rtn)(void) 返回值是void类型的指针函数 vodi *restrict arg start_rtn的行参 例题1: 功能:测试建立一个新的线程 程序名称: pthread_test。

c #include

#include void *create(void *arg)。。。{ printf("new thread created 。。。。。 "); }int main(int argc,char *argv[])。

。。{ pthread_t tidp; int error; error=pthread_create(&tidp,NULL,create,NULL); if(error!=0) 。。。。。。{ printf("pthread_create is not created 。

。。 "); return -1; } printf("prthread_create is created。。。 "); return 0;} 编译方法:#gcc -Wall -lpthread pthread_test。

c 因为pthread的库不是linux系统的库,所以在进行编译的时候要加上-lpthread,否则编译不过,会出现下面错误thread_test。c: 在函数 ‘create’ 中:thread_test。c:7: 警告: 在有返回值的函数中,程序流程到达函数尾/tmp/ccOBJmuD。

o: In function `main':thread_test。c:(。text+0x4f):对‘pthread_create’未定义的引用collect2: ld 返回 1。

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值