Using shared resources by a time-critical thread (a thread that needs to execute within a deterministic amount of time) can introduce extra jitter to your real-time application. One such shared resource is the LabVIEW Memory Manager. It is responsible for dynamically allocating memory.
When a normal priority program is in possession of the Memory Manager, the rest of the threads, including the time-critical thread, must wait for the shared resource to become available. In such cases jitter is inevitably introduced in the time-critical thread. To resolve this issue, the thread scheduler temporary boosts the normal-priority application to run in the time-critical thread so that it can finish up quicker and release the Memory Manager. This phenomenon is known as priority inheritance or priority inversion. To avoid such situations National Instruments advises to avoid using shared resources. A solution in the case of the Memory Manager would be to preallocate memory for arrays.
Priority inheritance can be sometimes enhanced when mixing two priority scheduling schemes – at the VI level and at the Timed Loop level. For example, in Figure 3 we can see a time-critical subVI (red icon) and a Timed Loop fighting for the same memory resources. The race for shared resources between the time-critical subVI and the Timed Loop can lead to priority inheritance.
Figure 3. Example of using two different priority assignment schemes.
Figure 4 is the trace of another program which has a normal priority subVI and a time-critical subVI sharing a common resource – the Memory Manager. The green flags show dynamic memory allocation, and the orange flag shows priority inheritance. The execution of the time-critical thread was interrupted so that the normal priority subVI can be boosted up to run in the time-critical thread, and therefore release the shared resource quicker. This eventually affects the determinism of the time-critical subVI.
Figure 4. The green flags show dynamic memory allocation(accessing the Memory Manager).
Preallocating Arrays for Deterministic Loops
Avoiding Shared Resources and Priority Inversions for Deterministic Applications
LabVIEW Real-Time Memory Management
Avoiding Contiguous Memory Conflicts (RT Module)