当前位置:   article > 正文

Linux sleep的三种实现_linux select实现sleep

linux select实现sleep

1、采用select

  1. timeval timeOut;
  2. timeOut.tv_sec = useconds/1000000;
  3. timeOut.tv_usec = useconds%1000000;
  4. TLOG_INFO("tv_sec=%lld, tv_usec=%lld.", timeOut.tv_sec, timeOut.tv_usec);
  5. if (0 != select(0, NULL, NULL, NULL, &timeOut)){
  6. TLOG_INFO("select error");
  7. return false;
  8. }

2、nanosleep

  1. struct timespec req;
  2. req.tv_sec = useconds/1000000;
  3. req.tv_nsec = (useconds%1000000) * 1000;
  4. int ret = nanosleep(&req, NULL);
  5. if (-1 == ret){
  6. TLOG_ERROR ("nanousleep %8u not support.", useconds);
  7. }

3、usleep

usleep(useconds)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/225008
推荐阅读
相关标签
  

闽ICP备14008679号