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 )后,程序正常运行了。
阅读(823) | 评论(0) | 转发(0) |