A RTOS application can be structured as a set of independent tasks
Each task executes within its own context with no coincidental dependency on other tasks within the system or the RTOS scheduler.
Only one task within the application can be executing at any point in time and the real time RTOS scheduler is responsible for deciding which task this should be.
The RTOS scheduler may repeatedly start and stop each task as the application executes. The scheduler ensures that the processor context (register values, stack contents, etc) when a task is swapped in is exactly that as when the same task was swapped out. To achieve this each task is has its own stack. When the task is swapped out the execution context is saved to its stack.
The idle task is created automatically when the scheduler is started to ensure there is always at least one task that is able to run. It is created at the lowest possible priority to ensure it does not use any CPU time if there are higher priority application tasks in the ready state.