Benefits of Multithreaded Applications

Applications that take advantage of multithreading have numerous benefits, including the following:

More Efficient CPU Use

In many LabVIEW applications, you make synchronous acquisition calls to an instrument or data acquisition device. Such calls often take some time to complete. In a single-threaded application, a synchronous call such as this effectively blocks, or prevents, any other task within the LabVIEW application from executing until the acquisition completes. In LabVIEW, multithreading prevents this blocking. While the synchronous acquisition call runs on one thread, other parts of the program that do not depend on the acquisition, such as data analysis and file I/O, run on different threads. Thus, execution of the application progresses during the acquisition instead of stalling until the acquisition completes.

In this way, a multithreaded application maximizes the efficiency of the processor because the processor does not sit idle if any thread of the application is ready to run. Any program that reads and writes from a file, performs I/O, or polls the user interface for activity can benefit from multithreading simply because you can use the CPU more efficiently during these synchronous activities.

Better System Reliability

By separating the program onto different execution threads, you can prevent other operations in your program from adversely affecting important operations. The most common example is the effect the user interface can have on more time-critical operations. Many times, screen updates or responses to user events can decrease the execution speed of the program. For example, when someone moves a window, resizes it, or opens another window, the program execution effectively stops while the processor responds to that user interface event.

In a LabVIEW multithreaded application, user interface operations are separated onto a dedicated user interface thread, and the data acquisition, analysis, and file I/O portions of the program can run on different threads. By giving the user interface thread a lower priority than other more time-critical operations, you can ensure that the user interface operations do not prevent the CPU from executing more important operations, such as collecting data from a computer-based instrument. Giving the user interface lower priority improves the overall system reliability, including data acquisition and processing, the performance of LabVIEW, and the performance of the computer as a whole, by ensuring that data is not lost because an operator moves a window, for example.

Another example where multithreading provides better system reliability is when you perform high-speed data acquisition and display the results. Screen updates are often slow relative to other operations, such as continuous high-speed data acquisition. If you attempt to acquire large amounts of data at high speed in a single-threaded application and display all that data in a graph, the data buffer may overflow because the processor is forced to spend too much time on the screen update. When the data buffer overflows, you lose data.

However, in a LabVIEW multithreaded application with the user interface separated on its own thread, the data acquisition task can reside on a different, higher priority thread. In this scenario, the data acquisition and display run independently so the acquisition can run continuously and send data into memory without interruption. The display runs as fast as it can, drawing whatever data it finds in memory at execution time. The acquisition thread preempts the display thread so you do not lose data when the screen updates.

Improved Performance on Multiprocessor Computers

One of the most promising benefits of multithreading is that it can harness the power of multiprocessor computers. Many high-end computers today offer two or more processors for additional computation power. Multithreaded applications are poised to take maximum advantage of those computers. In a multithreaded application where several threads are ready to run simultaneously, each processor can run a different thread. In a multiprocessor computer, the application can attain true parallel task execution, thus increasing overall system performance.

In contrast, single-threaded applications can run on only a single processor, thus preventing them from taking advantage of the multiple processors to improve performance. Therefore, to achieve maximum performance from multithreaded operating systems and/or multiprocessor machines, an application must be multithreaded.