Re:No nuances, just buggy code (was: related to Spinlock imp...
by gpderetta on Sunday January 05, 2020 @07:41AM
(#21961020)
Beacuse it would act as as an even worse sched yield.
[ Parent
| on HN ]
Re:No nuances, just buggy code (was: related to Spinlock imp...
by colonwqbang on Sunday January 05, 2020 @05:02PM
(#21964467)
I 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.
Re:No nuances, just buggy code (was: related to Spinlock imp...
by mritun on Sunday January 05, 2020 @04:26PM
(#21964230)
Calling sleep(1) instead of thread yield is faster - see the twitter thread for a proof.
Re:No nuances, just buggy code (was: related to Spinlock imp...
by de_watcher on Monday January 06, 2020 @10:04AM
(#21969619)
Still worse: it's a confusing code, and it's also confusing that it's faster.