4 ms·
It's explained in the linked post. Why don't you want to call sleep?
by colonwqbang 7y ago
It's explained in the linked post.
Why don't you want to call sleep?
- gpderetta 7y agoBeacuse it would act as as an even worse sched yield.
- temac 7y agoNot in every cases, but both are certainly suboptimal compared to a diretected wake up.
- deleted 7y ago[deleted]
- mritun 7y agoCalling sleep(1) instead of thread yield is faster - see the twitter thread for a proof.
- de_watcher 7y agoStill worse: it's a confusing code, and it's also confusing that it's faster.
- colonwqbang 7y agoI guess I can't really see the use case here. If you want to sleep, it's usually because you're waiting for something: file descriptor, semaphore/mutex, or a certain amount of time to pass. If none of these conditions apply, can't you just continue to run and let the scheduler do its work? (maybe with an appropriate nice setting if you are doing "less important" work). The scheduler itself uses fixed time interrupts for its basic functions, so "sleep(fixed_time_interval)" is what you will get in the end anyway on a preemptive system.