win10电脑桌面图标模糊 | win10系
773 2023-04-02 18:33:01
利用select 函数 实现sleep达到纳米级 。
当然这个数据计算出来不准确,本身就包含程序执行本身消耗的数量。
原理是把select read write except fd_set 全部设为NULL,这样select 就可以等待指定的时间。
#include <sys/select.h>#include <stdio.h>#include <time.h>#include <sys/time.h>int main(){ struct timeval tv; struct timeval start,stop; tv.tv_sec=2; tv.tv_usec=50000; gettimeofday(&start,NULL); //睡觉指定时间 select(1,NULL,NULL,NULL,&tv); gettimeofday(&stop,NULL); //计算时间差 printf("took %ld",stop.tv_usec+1000000*stop.tv_sec- start.tv_sec*1000000-start.tv_usec); return 0;}
地址 http://my.oschina.net/robinyao/blog/531798