> Maybe Dr.vi would consider composing a mini-series on the LabVIEW
> execution model.
>
> Anyway, a problem hit my desk a couple days ago. Apparently on one of
> our systems, my boss was trying to print 30 pages in about a minute
> and found, despite my hopeful threading model, it was interfering with
> DAQ. I thought I was a stress tester, but he really gets into it.
> Anyway, I think my printing must be executing on my DAQ thread since
> it has top priority?
>
Perhaps Dr. VI will do something like this, you should suggest it on
that site. In the meantime, maybe I can give a quick summary.
VIs have a setting for execution system and priority. This becomes
their preference, and with no external influences, this is where they
will begin and end their execution. The primary external influence, is
their caller. A low priority subVI called by a high priority VI will
inherit its caller's priority and become high priority. In addition,
most VIs are set to run in "Same as Caller" execution system, meaning
they inherit everything. This keeps the overhead of context switches
from overwhelming your computations.
So, a VI controls where it starts and stops execution, but since it can
call other subVIs, these subVIs may switch to others. They could use a
separate system, or a higher priority. Additionally, there are certain
tasks that can only be carried out by the UI thread. I'll try to list
them in a second, but these nodes will switch to the UI thread. Since
some diagrams my loop continuously doing nothing but tasks that require
the UI, the execution system lazily switches back.
For example, if a VI is set to run in Other, and it calls the VI Server
to query a panel location. The VI Server property node must run in the
UI thread, so a context switch takes place. Upon return from the VI
Server, the choices are stay in UI until we are forced to switch to
something else, or stay in UI in case the next thing needs it too. So a
diagram that runs in Other and makes repeated calls to a VI Server
property node runs faster with the amortized/lazy method of switching.
So, what has to run in the UI.
Orange CINs and DLLs -- they aren't thread safe and must be serialized
to the same thread each time.
VI Server property, method, open, and close nodes -- they modify or
inspect data structures that must be protected. They also do things
like open a panel, which can only be done from the UI thread.
Control/indicator property nodes -- same as VI Server, but just to be clear.
Menu, help, and most other nodes in the Application Control palette.
And that is all that I can think of off the top of my head. Things like
reading a terminal, a local, or the event structure do not switch to the
UI thread, but they do have to mutex with it, so they can be affected
slightly by its execution, but then every node that allocates memory is
mutexed, so that isn't so special.
To get to your printing issue. Printing always takes place in the UI.
It will not run in the DAQ thread. They can affect your DAQ operation
at some mutex point, such as the memory manager, or they could affect it
where it relies upon the UI thread. Ideally, if your DAQ operation is
high priority, it will not allow UI to affect its operation, so it will
decouple the UI from the acquisition. Your printout could also be
affecting DAQ because it is spooling out to disk while DAQ is trying to
log to disk.
Finally, keep in mind that no matter what you do to your diagram, the
underlying OS does what it wants. You mentioned the site that talks
about hi-res timers and high-priority tasks. I was looking at the
measurement with the author of those papers and saw high priority tasks
suspended for hundreds of milliseconds of time so that the OS could do
something as simple as unminimizing another application's window. So in
the end, your are only giving the OS hints and suggestions, and it can
all be derailed by the OS.
Now that I've given you the gloomy view, many times the MS OSes are
managable provided you keep the high priority systems sufficiently
decoupled from the rest of the app and you test lots of other
interactions, such as printing.
Greg McKaskle