Creating Deterministic Applications with the Real-Time Module
- Updated2025-02-17
- 3 minute(s) read
Creating Deterministic Applications with the Real-Time Module
Deterministic applications benefit from multithreading and from the priority-based scheduling model of the real-time operating system (RTOS). When creating deterministic applications, divide and separate application tasks to create multithreaded applications that receive dedicated processor resources based on the priorities set by the RTOS.
Multithreading
Single-CPU computers achieve multitasking by running one application for a short amount of time and then running other applications for short amounts of time. As long as the amount of processor time allocated for each application is small enough, computers appear to have multiple applications running simultaneously. Systems with multiple CPUs, on the other hand, can achieve true parallelism.
Multithreading applies the concept of multitasking to a single application by breaking it into smaller tasks that execute for short amounts of time in different execution system threads. A thread is a completely independent flow of execution for an application within the execution system. Multithreaded applications maximize the efficiency of the processor because the processor does not sit idle if there are other threads ready to run. An application that reads from and writes to a file, performs I/O, or polls the user interface for activity can benefit from multithreading because it can use the processor to run other tasks during breaks in these activities.
Priority-based Scheduling Model
The RTOS on RT targets uses a combination of round robin and preemptive scheduling to execute threads in the execution system.
Round robin scheduling—Applies to threads of equal priority. Equal shares of processor time are allocated among equal priority threads. For example, each normal priority thread is allotted 10 ms to run. The processor executes all the tasks it can in 10 ms and any remaining tasks at the end of that period must wait to complete during the next allocation of time.
Preemptive scheduling—Higher priority threads execute immediately while lower priority threads pause execution. A time-critical priority thread is the highest priority and preempts all priorities.
Priority of Timed Structures
LabVIEW executes timed structures threads below time-critical priority and above high priority. You can specify the priority level of Timed Loops relative to other timed structures within a VI by setting the priority of the Timed Loop. Use the Configure Timed Loop Dialog Box to configure a timing source, period, priority, and other advanced options for the execution of the Timed Loop.
Dividing Tasks to Create Deterministic Multithreaded Applications
Deterministic applications depend on deterministic tasks to complete on time, every time. Therefore, deterministic tasks need dedicated processor resources to ensure timely completion. Dividing tasks helps to ensure that each task receives the processor resources it needs to execute on time.
Separate deterministic tasks from all other tasks to ensure deterministic tasks receive enough processor resources. For example, if a control application acquires data at regular intervals and stores the data on disk, you must handle the timing and control of the data acquisition deterministically. However, storing the data on disk is inherently a non-deterministic task because file I/O operations have unpredictable response times that depend on the hardware and the availability of the hardware resource. You can use Timed Loops or VIs with different priorities to control the execution and timing of deterministic tasks.