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是两个参数;