Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1027983
  • 博文数量: 288
  • 博客积分: 10306
  • 博客等级: 上将
  • 技术积分: 3182
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-12 17:00
文章分类

全部博文(288)

文章存档

2011年(19)

2010年(38)

2009年(135)

2008年(96)

我的朋友

分类: C/C++

2009-09-08 11:49:29

sleep( 0 ) 的作用:

    A   value   of   zero   causes   the   thread   to   relinquish   the   remainder   of   its   time   slice   to   any   other   thread   of   equal   priority   that   is   ready   to   run.   If   there   are   no   other   threads   of   equal   priority   ready   to   run,   the   function   returns   immediately,   and   the   thread   continues   execution.


问题的引起:
    在MSDN的示例上有一个CMutex的示例程序,将些示例程序在VS71环境下运行时,程序立即报错,错误提示是在显示线程中出错,大概位置是:
 int CDisplayThread::Run()
 {
  ...
strBuffer = _T("Dspy: ");
strBuffer = strTmp + m_pOwner->m_strNumber;

-> if (fSyncChecked)  //在此处出错了
sLock.Unlock();

// Add the string form of the number to the list box.
m_pOwner->AddToListBox(strBuffer);
 }

    
将int CCounterThread::Run()函数中的Sleep(0)改为Sleep( 10 )后,程序正常运行了。
阅读(794) | 评论(0) | 转发(0) |
0

上一篇:线程间通信之一

下一篇:CLSID与ProgID

给主人留下些什么吧!~~