What exactly happens with a sleeping stream

I was wondering how the task scheduler in the operating system handles sleeping threads.

By this, I mean that the sleeping thread is still checked by the scheduler or simply skipped completely when it turns out which thread is active for the next 10 ms or at least from it.

My reason for asking about this is to find out if the sleeping thread consumes CPU cycles (albeit very few).

Does anyone know what is going on?

And do you know if it differs from Windows to Linux?

+4
source share
2 answers

A thread starts when the processor executes instructions for that thread. The scheduler passes the processor to executable threads. A sleeping thread is simply an entry into the internal scheduler tables; this thread does not consume the CPU for itself, since the scheduler knows that the thread is not working, and therefore does not give it a CPU. The entry conceptually contains the time at which the flow awakens.

Hibernation may have an indirect cost during the management of the scheduler itself. It really depends on the structures and algorithms used by the scheduler; The Linux kernel scheduler is rumored to be very good at managing thousands of sleeping threads without taking too much time to decide which thread to start. Some other operating systems are also not charged, but, as a rule, this effect is negligible when the total number of threads / processes is less than a thousand.

+9
source

It depends on the implementation of the OS, but usually there is a data structure with a "planned thread" to improve work efficiency.

But some kind of service task, you probably have to look at the list of all existing threads sometimes, even if not in every planning cycle.

0
source

Source: https://habr.com/ru/post/1301846/


All Articles