码迷,mamicode.com
首页 > 编程语言 > 详细

线程的创建pthread_create.c

时间:2016-06-24 12:55:56      阅读:138      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!