You are right: the processes and threads are the same from the point of view of the Linux scheduler. These tasks are queued in accordance with the scheduler rules and wait for their turn.
There are scheduling rules, such as priority or proximity of the processor (to prevent the thread from moving to another core and storing cache data).
A context switch can occur on the kernel every fixed period of time (time slice), because the CPU automatically runs some kernel code periodically to allow prevention. Depending on the scheduler rules, a task can be performed for many time fragments. A context switch can also occur when a thread calls functions that make it impossible (for example, waiting for I / O).
In some cases, if not all, there is one scheduling process for the kernel that does all of this.
There is also a similar question on superuser
source share