使用select实现sleep,是否适合用于多个线程同时调用
夏灯 2018-04-02 10:02:47 void timer_sleep(unsigned long seconds)
{
struct timeval tv;
tv.tv_sec=seconds;
tv.tv_usec=0;
int err;
do{
err=select(0,NULL,NULL,NULL,&tv);
}while(err<0 && errno==EINTR);
}
func1()
{
while (1) {
timer_sleep(1);
std::cout << "func1.."<<std::endl;
}
}
func2()
{
while (1) {
timer_sleep(1);
std::cout << "func2.."<<std::endl;
}
}
new std::thread(func1)
new std::thread(func2)