qThe resource management is used to co-ordinate concurrent accesses of several tasks with different priorities to shared resources
ve.g.management entities (scheduler), program sequences, memory or hardware areas.
vThe resource management can optionally be extended to co-ordinate concurrent accesses of tasks and interrupt service routines.
qResource management ensures that
vtwo tasks cannot occupy the same resource at the same time.
vpriority inversion cannot occur.
vdeadlocks do not occur by use of these resources.
vaccess to resources never results in a waiting state.
qIf the user requires protection against interruptions not only caused by tasks, but also caused by interrupts, he/she can also use the operating system services to enable/disable interrupts which do not cause rescheduling.
qRestrictions when using resources
vTerminateTask,ChainTask,Schedule,WaitEvent shall not be called while a resource is occupied.
vInterrupt service routine shall not be completed with a resource occupied.
qScheduler as a resource
vIf a task shall protect itself against preemptions by other tasks, it can lock the scheduler.
vThe scheduler is treated like a resource which is accessible to all tasks.
优先级反转(低优先级的任务T4占有信号量S1,导致最高优先级的任务T1不能使用S1而进入等待状态,而此时比T1优先级低的任务T2,T3得以运行)
死锁(任务T1占用信号量S1,等待S2;任务T2占用信号量S2,等待S1)
qOSEK Priority Ceiling Protocol(优先级天花板协议,优先级最高协议)
vTo avoid the problems of priority inversion and deadlocks:
§At the system generation, to each resource its own ceiling priority is statically assigned.
üThe ceiling priority shall be set at least to the highest priority of all tasks that access a resource or any of the resources linked to this resource.
üThe ceiling priority shall be lower than the lowest priority of all tasks that do not access the resource, and which have priorities higher than the highest priority of all tasks that access the resource.
§If a task requires a resource, and its current priority is lower than the ceiling priority of the resource, the priority of the task is raised to the ceiling priority of the resource.
§If the task releases the resource, the priority of this task is reset to the priority which was dynamically assigned before requiring that resource.
qInternal Resources
vInternal resources are resources which are not visible to the user and therefore can not be addressed by the system functions GetResource and ReleaseResource.
§managed strictly internally within a clearly defined set of system functions.
§the behaviour of internal resources is exactly the same as standard resources (priority ceiling protocol etc.).
vInternal resources are restricted to tasks.
§Atmost one internal resource can be assigned to a task during system generation. vIf an internal resource is assigned to a task, the internal resource is managed asfollows:
§The resource is automatically taken when the task entersthe running state,except when it has already taken the resource.
üAs a result, the priority of the task is automatically changed to the ceiling priority of the resource.
§At the points of rescheduling, the resource is automatically released.
vInternal resources can be used in all cases when it is necessary to avoid not-wanted rescheduling within a group of tasks.