Linux线程创建过程剖析.docxVIP

  • 6
  • 0
  • 约1.01万字
  • 约 12页
  • 2016-08-02 发布于安徽
  • 举报
Linux线程创建过程剖析.docx

/yetyongjin/article/details/7673837pthread_create线程创建的过程剖析概述在Linux环境下,pthread库提供的pthread_create()API函数,用于创建一个线程。线程创建失败时,它可能会返回ENOMEM或EAGAIN。这篇文章主要讨论线程创建过程中碰到的一些问题和解决方法。创建线程首先,本文用的实例代码example.c:/* example.c*/#include?stdio.h#include?stdlib.h#include?unistd.h#include?pthread.hvoid?thread(void){??int?i;??for(i=0;i3;i++)??printf(This is a pthread.\n);??sleep(30);}int?main(int?argc,char?**argv){??pthread_t id;??int?i,ret;??ret=pthread_create(id,NULL,(void?*) thread,NULL);??if(ret!=0){??printf (Create pthread error!\n);??exit (1);??}??for(i=0;i3;i++)??printf(This is the main process.\n);??pthread_jo

文档评论(0)

1亿VIP精品文档

相关文档