pthread 等待

来源:互联网 发布:英美澳加新 知乎 编辑:程序博客网 时间:2024/06/05 09:08

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

原创粉丝点击