INtime® 3.1 Software - tenAsys
INtime® 3.1 Software - tenAsys
INtime® 3.1 Software - tenAsys
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 3: About INtime software’s RT kernel<br />
Regions<br />
A region is a single-unit semaphore with special suspension, deletion, and priorityadjustment<br />
features. Regions provide mutual exclusion for resources or data; only one<br />
thread may control a region at a time; only the thread in control of the region can<br />
access the resource or data protected by a region. Once a thread gains control of a<br />
region, the thread cannot be suspended or deleted until it gives up control of the<br />
region. When the running thread no longer needs access, it exits the region, which<br />
enables a waiting thread to obtain control of the region and thus access the resource or<br />
data protected by that region.<br />
Regions have a thread queue where threads wait for access to the region. The queue<br />
may be FIFO- or priority-based.<br />
Priority inversions<br />
Regions also have a priority-inversion avoidance mechanism when the region’s thread<br />
queue is priority based.<br />
Then, if a higher-priority thread tries to enter a busy region, the priority of the thread in<br />
the region is raised temporarily so that it equals the waiting thread's priority. This<br />
helps prevent priority-inversion, as shown in this example:<br />
1. Thread A is the running thread. It is a low-priority thread with control of a region,<br />
accessing some data. The region has a priority queue. The only other thread that<br />
uses the data is thread C, a high-priority thread that is not ready to run.<br />
2. Thread B, a medium-priority thread, becomes ready to run and preempts A.<br />
3. Thread C becomes ready to run and preempts B. It runs until it tries to gain control<br />
of the region. Thread A's priority is raised to equal thread C's priority until thread<br />
A releases the region; then its priority returns to its initial level.<br />
4. When thread A releases the region, thread C receives control of the region and uses<br />
the data. When thread C completes, thread B runs.<br />
Without the priority inversion avoidance mechanism, thread B would have preempted<br />
A while A had control of the region; C would have preempted B, but would have been<br />
unable to use the data because A had control of the region.<br />
Deadlocks<br />
Regions require careful programming to avoid deadlock, where threads need<br />
simultaneous access to resources protected by nested regions, and one thread has<br />
control of one region while the other thread has control of another. To avoid deadlock,<br />
all threads must access nested regions in the same, arbitrary order, and release them in<br />
the same reverse order.<br />
37