RTOS Shared Resource Protection-Summary of shared resource protection between tasks and re-discussion of deadlock

Summary of task-task shared resource protection and re-discussion of deadlock

Task-Summary of methods for protecting shared resources between tasks

overview

In this chapter, we learned that because the hardware and software resources of the device are limited, in order to maximize the use of each resource of the device, different tasks may have read and write access to the same shared resource, thereby destroying the accuracy of the shared resource. integrity. We came up with some examples, such as two separate tasks that perform operations of adding 1 and subtracting 1 to a global variable ten times. Is the value of the global variable finally 0? For another example, the problem of one hour's speed may appear in a structure representing time.

Shared resources : Global variables , peripherals, memory blocks, etc. that can be used by more than two concurrent programs (including tasks and interrupts) at the same time are called shared resources.

The core of ensuring shared resources is time-sharing exclusive , and there are two implementation methods:

1) Lock-unlock mechanism , that is, during the running of the program, the locked resource is completely managed by a certain task, and other threads cannot access the shared resource unless the lock is unlocked. Such mechanisms can include methods such as critical sections, off-scheduling, semaphores, and mutexes.

2) Request-execution mechanism , that is, the access right to a resource is owned by a separate task, and other tasks can only indirectly use the resource by initiating a request to the task. This mechanism is mainly the implementation of guardian tasks.

FreeRTOS provides a variety of features to realize the protection of shared resources, but the best protection method is to carefully design applications, choose appropriate mutual exclusion strategies, and reduce shared resources.

Guess you like

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