LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Realtime - Calls to Shared Library Node are not being Prempted by Higher Priority (time-critical) Loops

From my simple test I believe that once LabVIEW enters a Call Shared Library Node it cannot perform a context switch to a higher priority timed loop. This is in conflict with the PharLap/LVRT documentation I've seen that says the highest priority thread will always run.

I made a simple test case using two timed loops and a nearly empty DLL made using Visual Studio C++ 2005.

One timed Loop (Loop A) is placed using 1ms period and priority 200
Another timed loop (Loop B) is placed using 50ms period and priority 100

Loop A compares its current loop iteration and if it is greater than 2000 it sets its stop condition to true.

Loop B compares its current loop iteration and if it greater than 2000 it sets its stop condition to true (2000 * 50ms = 100seconds)
Loop B also has one "Call Shared Library" node which points to a DLL. The DLL function being called is called WhileLoop() and is simply:

void WhileLoop()
{
    while(1)
   {
       //do nothing
    }
}

When I execute this code I observe CPU load on my 8196 PXI to go to 100% which I would expect from a while(1) loop however the loops never exit and processor utilization remains at 100% (even after 100 seconds).

The comparison in LoopB is not really needed if the execution never returns from the while(1) loop then of course it will never exit but my biggest concern is the higher priority loop (Loop A) also does not appear to exit.

In my real application I have time critical code but I am using DLL calls in lower priority timed loops and these are causing excessive jitter in my time critical code.

Does anyone have any thoughts or input on how I could solve this? I need to make DLL calls and I can't predict how long the DLL calls will take (non-deterministic parts of the application).

Thanks
-Alex-

EDIT: My DLL calls are set to run in "any thread" and I'm using LabVIEW 8.5 and realtime 8.5



Message Edited by AlexDubya on 01-23-2008 05:51 PM
0 Kudos
Message 1 of 13
(4,687 Views)

Hi Alex,

What if your run time for Loop A is longer? Does your program then transfer to your second loop? Which loop does the program never leave? Can you post your code for us to look at?

Regards,

Hillary E
National Instruments
0 Kudos
Message 2 of 13
(4,656 Views)
Hi Hillary,
 
If Loop A is longer I see no change.
 
Loop B never exits beacuse Loop B has a non-terminating DLL call.
 
Attached is a simple visual studio project, a labview project, and a GIF file showing the settings related to multithread and multithreaded DLL and debug in Visual studio 2005.
 
Thanks for the reply.
 
 
0 Kudos
Message 3 of 13
(4,651 Views)
Hi Alex,
 
Can you post your dll with the while loop function? This is interesting and we are looking into it more here at NI. You should also try checking your dll with the DLL Checker.
Regards,

Hillary E
National Instruments
0 Kudos
Message 4 of 13
(4,625 Views)
Here is the DLL.
 
It is also included in my previously attached file. Rename it from .gif though 😛
0 Kudos
Message 5 of 13
(4,622 Views)

Alex,

I configured and ran the vi on my PC and the top priority loop ran for the expected number of times. The program only hung after it finished the top loop. Are you deploying this to your RT target or just on your host computer? Can you give us more specifics on your system?

Regards,

Hillary E
National Instruments
0 Kudos
Message 6 of 13
(4,576 Views)
Your top loop finished executing? Thats interesting - I can't seem to get the top loop to run at all on my PXI-8106 and PXI-8196 and Desktop PC running Realtime (all are LV8.5).
 
I've tested the top loop being starved in several ways the most robust I can find is using a DAQmx task to write a bit high when i enter the loop and write a bit low when I exit the loop - then I use a bench scope to look at the waveform.
 
I never see the bit change on the scope when the second loop is enabled.
 
It makes me thing I've done something silly on my end but I can't figure out what.
 
0 Kudos
Message 7 of 13
(4,575 Views)
So you are running this on your RT Target and not on your regular PC? I have yet to try it on an RT Target just on my regular computer. We are really going to have to look into this more on our end.
Regards,

Hillary E
National Instruments
0 Kudos
Message 8 of 13
(4,538 Views)
Correct I am running this ONLY on LVRT systems. Maybe try to replicate this on your end using a PXI?
0 Kudos
Message 9 of 13
(4,533 Views)
Alex,

We have reproduced this issue and have noticed the same behavior.  The top timed loop is, in fact, running to completion, you just cannot see the LED on the front panel flicker since the front panel has a lower priority than both of the timed loops.  You can connect a monitor up to your PXI controller and observe this since the monitor is at a higher priority than the loops.  Add a RT FIFO Debug.vi to the top loop and output a value to the monitor.  When you run the VI, you will see 100 values appear on the screen, and then the controller will continue to run the second loop with 100% processor use due to the infinite loop in your DLL.  Therefore the top loop is not being starved, but rather the front panel is.  I hope this helps. 

Brian T
Applications Engineer
0 Kudos
Message 10 of 13
(4,480 Views)