首页 > 编程语言 > 详细

线程的创建pthread_create.c

时间:2016-06-24 12:52:56      阅读:241      评论:0      收藏:0      [点我收藏+]
 1 #include <stdio.h>
 2 #include <pthread.h>
 3 #include <stdlib.h>
 4 #include <errno.h>
 5 
 6 void *pthread_fun(void *arg)
 7 {
 8   int b;
 9   b = *(int *)arg;
10   printf("b = %d \n",b);
11   int i = 5 ;
12   while(i > 0)
13    {
14      printf("pthread start \n");
15      sleep(1);
16      i -- ;
17    }
18 }
19 int main()
20 {
21      pthread_t pthread;
22      int a =10;
23 #if 0 
24      if (pthread_create(&pthread,NULL,pthread_fun,NULL) < 0)
25       {
26           perror("fail to pthread_create");
27           exit(1);
28       }
29 #endif
30 #if 1
31     if (pthread_create(&pthread,NULL,pthread_fun,&a) < 0)
32     {
33        perror("fail to pthread_create");
34        exit(1);
35     }
36 #endif
37     printf("pthread create success\n");
38     pthread_join(pthread,NULL);//等待线程的退出
39     printf("pthread exit \n");
40     return 0;
41 }

 

线程的创建pthread_create.c

原文:http://www.cnblogs.com/renchong/p/5613774.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!