When we use pthread to create a thread, we can specify the scheduling policy-sched_other (default), sched_rr, and sched_fifo. Here we will talk about two real-time policies: sched_rr and sched_fifo.
Let's take a look at the effect. We have created four sub-threads to specify the highest priority (for specific policies ):
For tasks with the same priority, sched_rr is assigned to each task a specific time slice and then rotated and executed in turn. sched_fifo is used to schedule the next task after the task is executed, the order is based on the order of creation. Sched_rr schedules a thread based on the time slice. When the time slice is used up, no matter how high the thread priority is, it does not run, but enters the ready queue, waiting for the next time slice to arrive.
However, as shown in figure 1, when the thread5798 time slice is used up, the thread immediately preempys the preemption and obtains a time slice.. By the way, the length of time slice is determined by Linux's experience, that is, a time slice that can be as long as possible and maintain a good time.