共 1,395 篇文章
共 6,621 篇文章及评论
博客分类
Blog Roll
- Association for Computing Machinery TechNews (ACM)
- Go Parallel! (Dr. Dobbs)
- HPCwire (Tabor Communications, Inc.)
- insideHPC (John West)
- Joe Duffy's Weblog (Microsoft)
- Microsoft Parallel Programming Development Center (Microsoft Germany)
- MultiCoreInfo.com
- scalability.org (Scalable Informatics)
- Software Dev Blog (Intel Germany)
- Soft Talk Blog (Intel United Kingdom)
- The Moth (Microsoft)
Archives
帖子来自 yeyuangen 
多线程编程(一):线程创建和退出
作者: yeyuangen (1 篇文章) 日期: 十月 28, 2011 在 1:29 下午
评论 (2)
一、引言 二、实例 以下实例中创建了2个线程,其中第一个线程是在程序运行到中途时调用pthread_exit函数退出,第二个正常退出。在主线程中,收集这两个线程的退出信息,并释放资源。从实例可以看出,这两个线程是并发运行的。 /*thread.c*/ #include #include void thread1(void) { int i=0; for(i=0;i<6;i++) { printf("This is a pthread1.\n"); if(i==2) pthread_exit(0); //线程退出 sleep(3); //线程1睡眠,将CPU让给其它线程 } } void thread2(void) { int i; for(i=0;i<3;i++) printf("This ...
