Home |
RTKernel-32 Programming Manual Multitasking, Real-Time, and RTKernel-32 Alternate APIs for RTKernel-32 Preemptive or Cooperative Multitasking? Mutual Exclusion Starting Objects' Methods as Tasks Performance and Interrupt Response Times Task Switches in Cooperative Scheduling Using the FPU in Interrupt Handlers |
Mutual ExclusionAssume that two or more tasks have to manipulate the same global data object. In order to assure consistency of the data, care has to be taken that only one task accesses the data at any one time. In this case, a semaphore can be utilized for coordination. The semaphore is initialized with one event. This event thereafter represents the permission to access the data. Before a task modifies the data, it calls RTKWait with the corresponding semaphore in order to get permission to access the data. When a task is finished accessing the data, it must call RTKSignal to store the access permission in the semaphore and thus enable other tasks to access the data. If all tasks adhere to this protocol, no more than one task will ever change the data at any one time. This algorithm can be used with counting, binary, resource, and mutex semaphores. Resource and mutex semaphores are especially suited for this purpose, because of priority inheritance, safe Suspend/Terminate operations, and - for resource semaphores - the Debug Version's error checking. Win32 Critical Sections are also designed for mutual exclusion and are frequently faster than semaphores, but do not implement priority enheritance or suspend/terminate protection.
|