Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 5 Sequences & Scripting

5.21 Sequence Threads and Thread Priority

Scroll Prev Top Next More

When sequences are started they run in their own thread.  A thread is like a separate program running concurrently with other threads inside of DAQFactory.  Because each sequence runs in its own thread, they can all perform different tasks at the same time.  Sequences called as functions either from another sequence or expression run in the thread of the calling sequence or expression.  Events for channels and PID loops run in the thread of the loop or acquisition.  The events of many components alway runs in the one and only main application thread.  The main application thread is the thread that the user interface of DAQFactory runs in.  This is where the mouse gets moved, components get displayed, and menu items get processed.  The reason this distinction is important is two fold:

1) sequences running in the main application thread should be fast otherwise they will cause the user interface to be sluggish.  This is because the sequence steps have to be executed before the rest of the user interface can respond.  If you have wait or delay statements in your sequence then you can give the user interface time to respond.  Even a wait(0) will help.  Wait(0) tells windows to go do something else for a bit and then come back when other things are done.

2) some functions only work in the main application thread.   These functions will generate an error if they are called from a secondary thread.

Threads within DAQFactory and Windows have priority levels.  This determines which threads get access to the CPU first when requested.  By default, sequences run at the highest priority within DAQFactory along side acquisition loops.  This means that if you write an infinite loop in a sequence or anything else that would use a lot of processor power, it may hang everything in DAQFactory but the data acquisition loops.  The data acquisition loops have the same priority so share in the CPU usage.  The other parts of DAQFactory run at lower priority and are starved out by your sequence.  A sequence that is waiting does not require the CPU and allows other lower priority threads to run, so adding delay or wait statements inside your sequence will avoid this problem.  

Alternatively, you can lower the priority level of your sequence.  The thread priority is an option at the top of the Sequence view.  There are 6 different levels, 0 through 5.  The level of different parts of DAQFactory are displayed when selecting the thread priority.  In general, leave the priority at its default value.  But if you want to create a sequence that uses a lot of processor power, for example a big while loop analyzing a large data set, put the thread priority at 0 and your sequence will run after DAQFactory is finished with all other tasks.  The following loop will actually work fine if the sequence thread priority is set to 0:

 

while(1)

endwhile

This is an infinite loop that does nothing but use up the CPU.  But, if the thread priority is set to 0, it only uses left over CPU power after Windows and DAQFactory are done using the CPU.

Tech Note: The 0 priority level is the windows idle priority and runs after everything else in windows.  Other levels are intermingled with other applications, though the highest couple of levels will be above most other applications.