Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45164
  • 博文数量: 14
  • 博客积分: 1485
  • 博客等级: 上尉
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-13 15:44
文章分类

全部博文(14)

文章存档

2012年(1)

2011年(2)

2010年(3)

2009年(8)

我的朋友

分类: C/C++

2011-03-08 09:48:28

#include
#include
#include
volatile static int nCount = 0;
void* frk_thread(void *param)
{
 while(1)
 {
  printf("nCount=%d\n", nCount);
  
  nCount++;
  
  usleep(100000);
 }
}
int main()
{
 int nStart;
 int nEnd;
 
 pthread_t thread_frk;
 
 pthread_create(&thread_frk, NULL, frk_thread, NULL);
 
 nStart = nCount;
 
 while(1)
 {  
  nEnd = nCount;
  
  if(nEnd - nStart >= 100)
   break;
  
  //printf("%d-%d=%d\n", nEnd, nStart, nEnd-nStart);
 }
 
 printf("over !\n");
 
 return 0;
}
 
gcc -Wall -O2 tc.c -o tc -lpthread 
阅读(611) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~