What is time slicing / round-robin scheduling?
Short answer: When several ready tasks share the same highest priority, the scheduler gives each a time slice and rotates between them in round-robin order. In FreeRTOS a slice is one tick (configUSE_TIME_SLICING). Tasks of different priorities are never time-sliced against each other: the higher-priority ready task always runs.
Example (1 ms tick, three tasks at priority 2, one at priority 3)
Priority 3 task blocked: A B C A B C A ... (each runs for one tick in turn)
Priority 3 task ready: H H H ... (A, B, C get nothing until H blocks)
Details
- A task that blocks before its slice ends gives up the rest of it; the next equal-priority task runs immediately.
- A task woken by an event does not necessarily run at once if a task of the same priority is running (it runs at the next tick or yield), unless the port/config says otherwise (
configUSE_PREEMPTIONwith yields on equal priority). - The idle task shares priority 0 with application tasks at priority 0;
configIDLE_SHOULD_YIELDcontrols whether it yields to them.
When to use equal priorities with time slicing: background jobs of similar importance (logging, housekeeping). For time-critical work, give tasks distinct priorities and let them block, rather than relying on slices.
Linux comparison: SCHED_RR is round robin among equal real-time priorities (100 ms default slice); normal tasks use weighted fair scheduling instead.