当前位置: 技术问答>linux和unix
超时问题的时间设置
来源: 互联网 发布时间:2017-01-04
本文导语: timespec m_tWaitTime m_tWaitTime.tv_sec = time(NULL) + m_nIntervalMilliseconds/1000; m_tWaitTime.tv_nsec = (m_nIntervalMilliseconds % 1000) * 1000000000; pthread_cond_timedwait(&m_tCond, &m_mutex, &m_tWaitTime);// 不准 m_nIntervalMilliseconds 设置 1000以...
timespec m_tWaitTime
m_tWaitTime.tv_sec = time(NULL) + m_nIntervalMilliseconds/1000;
m_tWaitTime.tv_nsec = (m_nIntervalMilliseconds % 1000) * 1000000000;
pthread_cond_timedwait(&m_tCond, &m_mutex, &m_tWaitTime);// 不准
m_nIntervalMilliseconds 设置 1000以上 比如 2000 3000都比较准。但是小于1000就明显不准了 比如900
m_tWaitTime.tv_sec = time(NULL) + m_nIntervalMilliseconds/1000;
m_tWaitTime.tv_nsec = (m_nIntervalMilliseconds % 1000) * 1000000000;
pthread_cond_timedwait(&m_tCond, &m_mutex, &m_tWaitTime);// 不准
m_nIntervalMilliseconds 设置 1000以上 比如 2000 3000都比较准。但是小于1000就明显不准了 比如900
|
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock()