pthread 等待

pthread 等待

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <errno.h>

/*struct number{
int number;
char *string;
};*///;不可少
void *create(void *arg){
int i;
for(i=0;i<=10;i++){
sleep(2);
printf("In the process %d\n",i);
}
return (void*)0;
}

int main(int argc,char *argv[]){
pthread_t pthid;
int i;
int errno;
errno=pthread_create(&pthid,NULL,create,NULL);
if(errno){
printf("create pthread failure!\n");
exit(EXIT_FAILURE);
}
pthread_join(pthid,NULL);
printf("thread exit!\n");
for(i=0;i<10;i++){
printf("int the process %d\n",i);
}
return 0;
}
                  


[root@localhost sourcetemp]# ./pthread_block
In the process 0
In the process 1
In the process 2
In the process 3
In the process 4
In the process 5
In the process 6
In the process 7
In the process 8
In the process 9
In the process 10
thread exit!
int the process 0
int the process 1
int the process 2
int the process 3
int the process 4
int the process 5
int the process 6
int the process 7
int the process 8
int the process 9

 遇到的问题:

1.pthread_join是两个参数;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值