c++ linux Eventloop vs. sleep() vs select() -
i have so/dll program needs sleep -> check stuff -> sleep.
which better way perform operation:
// sleep loop while ( true ) { sleep( 1 ); // whatever time if ( flag_quit ) leave; if ( flag_something_else ) do_whatever(); }
or
// select loop while ( true ) { timeout.sec = 1.0; // whatever time timeout.msec = 0; zeroiftimedout = select( fdmax, fdlist, null, null, timeout ); if ( flag_quit ) break; // leave while loop if ( flag_something_else ) do_whatever(); if ( 0 == zeroiftimedout ) continue; // }
or
// well, write event loop in c++
the real questions are,
which option less processor intensive?
is there
yield()
both windows , linux replace sleep?if decide use in application, is, not in dll/so, there better way handle
stdin
select() method?would interruptable sleep better in method?
an infinite (well, until there's input) sleep accompanies
std::cin
orgetchar()
. sleep yield process?
Comments
Post a Comment