Consider an application where you have the following three tasks:
You can approach this example in the following three ways.
You can approach each task sequentially, as is shown in the following example.
Note the following issues in this approach:
This is the most common approach, and for many applications it is the best approach.
In the following example, each task runs independently and at different rates from the other tasks.
Data passes between tasks using local variables.
Note: This examples uses local variables for presentation purposes only. Using local variables might result in lost or duplicated data.
Note the following issues in this approach:
This first two issues seem like disadvantages, but you can take advantage of the issues. For example, suppose that the Acquire Data task also saves the acquired data to disk. This saved copy of the acquired data has all the data if you need a complete log of the data later. The other tasks can then run slower, skipping some data, and display only the latest data while analyzing the data.
Another advantage of this approach is that it allows prioritization. With some additional work, you can configure the three tasks so the Acquire Data task gets priority of execution over analysis and presentation. That way, slower computers can acquire and save data without getting errors.
Finally, consider the following more advanced approach.
Note the following issues in this approach:
Note: Because of the nature of queues, if the Analyze Data task does not keep up with the Acquire Data task, the queue fills up with data to be analyzed and the Acquire Data task must wait for the Analyze Data task to remove data before it can place additional data in the queue.
Data acquisition makes a particularly good example of this approach because buffered acquisition reliably stores data into a buffer and it is up to the program to remove data from the buffer before it is overwritten. If the data is overwritten, an error is returned and the acquisition stops. While this makes acquisition reliable because you never lose any data without an error, it also means that you must make sure acquisition tasks execute fast enough to avoid errors.
If you do not read data from the buffer fast enough to avoid getting an error and still perform analysis on the data, you have the following options:
If you use the multiple task approach in your application, a number of advanced topics can be powerful tools with that approach: