RTOS Interrupts - Using Critical Sections to Protect Shared Resources

RTOS Interrupts - Using Critical Sections to Protect Shared Resources

overview

The previous section described the competition for shared resources between interrupts and between interrupts and tasks. In order to protect shared resources, a critical section mechanism can be used to protect shared resources.

In the section of task and task shared resource protection - using critical section to protect shared resource , we have recognized the implementation principle and basic usage of critical section. Here is a summary of it again.

Fundamentals of Critical Sections

The critical section is a popular concept of a shared resource protection mechanism. Specifically, the critical section is a lock-unlock mechanism . After the critical section is established, the code is locked, and other tasks and interrupts cannot be accessed again. Enter this code unless unlocked.

The critical section can be implemented in many ways, usually by closing the global interrupt. The implementation of the critical section in ESP-IDF is to close all interrupts that are not larger than configMAX_SYSCALL_INTERRUPT_PRIORITYthe interrupt (including the SysTick interrupt).

As shown in the figure below, the code between entering the critical area and exiting the critical area in the code will exclusively use the CPU, and will not be interrupted by other interrupts and tasks. Therefore, access to shared resources in it is safe.

Guess you like

Origin blog.csdn.net/wangyx1234/article/details/128253363