4.2 Blocking Versus Non-Blocking Functions

A blocking function blocks a task from continued execution. When a task gets blocked, the RTOS will switch execution to a different task. This optimizes the CPU utilization because there will never be cycles where the CPU is doing nothing.

Typically tasks will block when they call a delay function, when they are waiting for communication or resources used by other tasks, or when an interrupt (ISR) is called. When calling vTaskDelay(ticksToDelay), the task will block for as many ticks as specified. The actual time the task will block depends on the tick rate which is specified in the configuration file.

When tasks share resources, they must wait for each other to finish using the resource before they can start using it themselves. Waiting for a resource like this is also called blocking. In order to create such behavior, semaphores and mutexes can be used. A more thorough explanation of shared resources and synchronization is found in the next section.