标签:
说明:在调用该函数前要先调用WSAStartup初始化Winsock
void uSleep(uint32_t usec) { struct timeval timeout; fd_set fds; FD_ZERO(&fds); int32_t fd = socket(AF_INET, SOCK_DGRAM, 0); FD_SET(fd, &fds); timeout.tv_sec = usec / 1000000; timeout.tv_usec = usec % 1000000; int ret = select(0, NULL, NULL, &fds, &timeout); if (0 > ret) { perror("select"); } closesocket(fd); }
利用select函数的定时返回功能在Windows上实现微秒级的cpu休眠
标签:
原文地址:http://www.cnblogs.com/tangxin-blog/p/5722873.html