I'm reading about SOS_SCHEDULER_YIELD and after lots of readings about internals, like clock intervals, threads and quantums I've got ok understanding of how it works.
But still one fundamental question bothers me - Why would worker thread voluntarily yield processor after 4ms quantum? As per my understanding because it's non-preemptive:
If it's running it should complete task
If it needs resource it will go back to wait queue.
It's not like thread is jumping between RUNNING and RUNNABLE statuses every 4ms, right? But there are cases where it will yield as we know and I am not sure why this would happen. What is happening with the thread at the time decision is made to remove it from RUNNING state.
EDIT: I realize there is a lot of questions about this wait type, but I am not looking into troubleshooting now, but instead I'd like to understand what can make hypotethical running thread yield CPU.