现在的位置: 首页 > 综合 > 正文

Linux创建线程

2017年12月19日 ⁄ 综合 ⁄ 共 552字 ⁄ 字号 评论关闭

 

  1. #include"stdio.h"  
  2. #include"pthread.h"  
  3. #include"unistd.h"  
  4. static shdata=4;  
  5. void *create(void *arg)  
  6. {  
  7.     printf("New pthread......\n");  
  8.     printf("shared data=%d \n",shdata);  
  9.     return(void *)0;  
  10. }  
  11. int main()  
  12. {  
  13.     pthread_t tid;  
  14.     int error;  
  15.     error=pthread_create(&tid,NULL,create,NULL);  
  16.     if(error!=0)  
  17.     {  
  18.         printf("thread is not created...\n");  
  19.         return -1;  
  20.     }  
  21.     printf("main pid is %d\n",getpid());  
  22.     sleep(1);  
  23.     printf("线程创建成功!\n");  
  24.     return 0;  
  25. }  
  26.  

 

本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/702536

【上篇】
【下篇】

抱歉!评论已关闭.