开发者社区> 问答> 正文

请教select定时偏差,linux平台

代码如下:
#include

include

include

include

include

include

include

include

int main()
{

while(1)
{
    struct timeval stStart, stEnd;
    gettimeofday(&stStart, NULL);

    struct timeval tv={0, 33000};
    select(0,NULL,NULL,NULL,&tv);

    gettimeofday(&stEnd, NULL);
    unsigned int iDelayUseTime = ((stEnd.tv_sec-stStart.tv_sec)*1000*1000+(stEnd.tv_usec-stStart.tv_usec));

    printf("use time:%u\n", iDelayUseTime);
    if(iDelayUseTime < 30000 || 35000 < iDelayUseTime)
        exit(0);
}
return 0;

}

运行结果:
screenshot

展开
收起
杨冬芳 2016-07-18 17:51:45 1776 0
1 条回答
写回答
取消 提交回答
  • 阿里云高级技术专家

    Note that the timeout interval will be rounded up to the system clock granularity, and kernel scheduling delays mean that the blocking interval may overrun by a small amount.
    到时间了内核也只是把这个线程丢进可调度队列,是不是实际分配cpu给它取决于调度策略。

    2019-07-17 19:58:11
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Alibaba Cloud Linux 3 发布 立即下载
ECS系统指南之Linux系统诊断 立即下载
ECS运维指南 之 Linux系统诊断 立即下载