06-29-2007
05:52 PM
- last edited on
05-20-2025
04:59 PM
by
Content Cleaner
I have a multithreaded application that runs 9 seperate while loops simultaneously. Most of the loops are entirely contained in parallel subVIs with normal priority and execution thread set to its caller (communication is handled via queues\user events\functional globals). Some of the loops are embedded in the top level VI itself, with their subVIs also set to normal priority\same-as-caller thread (for example, the UI loop). However, there is one loop (embedded in the top level VI) whose sole task is to respond to a DAQmx change detection event (via a registered dynamic event wired to an event structure), sample some digital lines, and send them for processing via a queued buffer. Due to various reasons, this event-driven (essentially interrupt-driven) digital aquisition is non-buffered (hardware-timed single-point), so it is critical that this loop have the highest priority in terms of execution, as often times this loop will need to respond, acquire, and queue data up to 50 times a second. I have set the subVIs in this critical loop to Highest priority and to the Data Aquisition thread. Additionally, I have programmatically set the thread priority of the application itself to High priority in Windows as shown in this KnowledgeBase article.
Have I done everything possible to ensure that this critical loop will run as deterministically and efficiently as possible given a (non-realtime) Windows environment? Am I missing anything else? (see attached picture for relevant section of code)
I'm aware that instead of while loops, it might be possible to use timed loops and set priorities to them. My concern with using this method is that the critical loop's only "wait function" (giving up thread priority) is waiting on the event structure within it. If I used a Timed Loop, there would essentially be two points in the cycle where thread priority is released. Additionally, if another (lower priority) timed loop is executing when my critical loop becomes ready to start again, it has to wait until the lower priority timed loop completely finishes before it can start the new cycle. This is not the behavior I want--I want the critical loop to only wait at the event structure, ready to seize thread priority from whatever else may be running when an interrupt is generated by the DAQmx event.
07-01-2007 11:58 PM - edited 07-01-2007 11:58 PM
Message Edited by Jarrod S. on 07-01-2007 11:58 PM
07-02-2007
12:01 AM
- last edited on
05-20-2025
05:00 PM
by
Content Cleaner
A Help page with some info...
P.S. Fantastic looking code.
Message Edited by Jarrod S. on 07-02-2007 12:02 AM
07-02-2007 10:17 AM
07-02-2007 10:33 AM
@Yuri33 wrote:
3) If I transition other loops in this program (some hidden in the "engine" subVIs) and set timed loop priorities, I am still concerned that the critical loop may be stuck waiting for other (lower priority) timed loops to finish executing, regardless of how the subVI priorities are assigned. According to the LabView help on timed structure priorities, once the priority of pending structures are compared, the selected structure must completely execute before the next structure starts. So if my critical loop and another loop want to start at the same time, then the critical loop will completely execute before the other, which is good. But once the critical loop finishes executing, it has to go back into the timed structure "queue," meaning that it must wait for any currently running (lower priority) timed structure to completely finish before it can start again (even if the priority of the critical loop allows it to jump to the head of the queue).
07-02-2007 10:54 AM
The following block diagram contains a Timed Loop and a Timed Sequence. The Priority value of the first frame of the Timed Sequence (200) is higher than the priority of the Timed Loop (100) and therefore executes first.
(multiple timed structures block diagram)
After the first frame of the Timed Sequence executes, LabVIEW compares the priority of other structures or frames that are ready to execute. The priority of the Timed Loop (100) is higher than the priority of the second frame of the Timed Sequence (50). LabVIEW executes an iteration of the Timed Loop and then compares the priority of the structures or frames that are ready to execute. The Timed Loop priority (100) is higher than the second frame of the Timed Sequence (50). In this example, the Timed Loop will execute completely before the second frame of the Timed Sequence executes.
07-02-2007 11:41 AM
07-02-2007 11:51 AM - edited 07-02-2007 11:51 AM
Message Edited by Yuri33 on 07-02-2007 11:51 AM