From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL Hogs User thread

Solved!
Go to solution

Dear All,

 

  I am calling a Cascon JTAG application from LabVIEW and using to to programme an FPGA. 

LabVIEW interfaces to Cascon by calling a set of DLLs via driver VIs supplied by Cascon.

 

The act of programming the FPGA takes a couple of minutes and the LabVIEW user interface is locked up for this time, even though the call comes from a consumer loop. 

 

I understand, from my research, that thread unsafe DLLs can be forced to run in the user thread.  Does anyone know how to switch this feature off so that the front panel doesn't lock up, bearing in mind that the frivers are from a reputable source? 

 

  Regards,

 

  Ian

 

 

0 Kudos
Message 1 of 10
(3,147 Views)

Switch off is not an option. The UI thread is a single thread and it exists exactly once and that's it.

 

The question is if your DLL requires to be run in the single threaded UI thread. That is a question only the DLL programmer can answer safely (if he even cares about that).

 

Changing the Call Library Node to run the function in any thread is an exercise you could try but it comes with a big caveat: While it may not crash your system it can have nasty side effects that can range from delayed crashes later on, to strange and unexplainable failures during execution of your function, or even random results.

You definitely want to make sure that you do not call other functions inside the DLL in parallel to this function while it is executing to be a little bit more on the safe side, but there is no guarantee. If the DLL somehow uses global resources like global variables or hardware IO (or God may safe you from this, Thread local storage across function calls) then you are in for a huge mess if you change the Call Library Node to run in any thread. And as already mentioned the only one who can tell you if such issues exist is the actual DLL programmer (and if you have a really awesome DLL documentation it may be explicitly stated in there, but such documentation is rare and far between as the programmer doesn't usually like to write it and the tech writer doing it doesn't have enough technical knowledge to care about such "minor" details).

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 10
(3,118 Views)

If you're using the Call Library function to use this DLL it's per default running in the UI thread and is an orange(?) node. If you r-click it you can change this to Run in any thread and it should turn yellow.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 10
(3,098 Views)

Thanks for all of the above gents,

 

   I have discovered that there is a Cascon VI in the drivers which decides whether to use UI thread or any thread, but, of course, it is locked so I can't peek inside.  I tried bypassing it and forcing 'any thread'  but it led to a crash further down the line, as predicted.  Unless Cascon can be persudaed to make a fix it looks like I am stuck with the long pauses.   I can't even create a moving 'BUSY' sign to tell users that it hasn't locked up.  How tiresome!

0 Kudos
Message 4 of 10
(3,091 Views)

Hi Barionics,

 


@Barionics wrote:

I can't even create a moving 'BUSY' sign to tell users that it hasn't locked up.


You can split your one application into 2 separate apps: one just handling the user interface and another app handling that JTAG device. Have them communicate using network protocols. This way your UI will still be able to react to user actions while the other app is blocked by those DLL calls…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 10
(3,083 Views)

@Barionics wrote:

Thanks for all of the above gents,

 

   I have discovered that there is a Cascon VI in the drivers which decides whether to use UI thread or any thread, but, of course, it is locked so I can't peek inside.  I tried bypassing it and forcing 'any thread'  but it led to a crash further down the line, as predicted.  Unless Cascon can be persudaed to make a fix it looks like I am stuck with the long pauses.   I can't even create a moving 'BUSY' sign to tell users that it hasn't locked up.  How tiresome!


You should be able to change the cursor to the Busy circle before calling the function.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 10
(3,079 Views)

Thanks for your thoughts Gerd,

 

   I had thought of that but my error handler, which is launched asynchronously, works in a similar way and is also locked up.  It looks like LabVIEW has one UI thread for all apps, and possibly the rest of Windows too.  Or am I wrong in this? 

 

Ian

0 Kudos
Message 7 of 10
(3,030 Views)

Thanks for the idea,

 

   The cursor is already a busy circle so no problems there.

 

   Ian

0 Kudos
Message 8 of 10
(3,029 Views)
Solution
Accepted by topic author Barionics

@Barionics wrote:

Thanks for your thoughts Gerd,

 

   I had thought of that but my error handler, which is launched asynchronously, works in a similar way and is also locked up.  It looks like LabVIEW has one UI thread for all apps, and possibly the rest of Windows too.  Or am I wrong in this? 


That definitely sounds bogus! Are you sure you launch your error handler as a seperate LabVIEW executable? How do you communicate to it from your LabVIEW program? If it is a seperate process you would need some interprocess communication like TCP/IP, shared memory or file IO.in order to communicate between the two. If you just launch it as asynchronous VI it will of course run in the same process, which is easy to communicate to with queues, etc. but shares the same UI thread.

 

Seperate processes can’t share the same thread as they run in completely independent virtual memory spaces and if there could be such a sharing between two processes that would be a huge security problem in Windows.

Rolf Kalbermatter
My Blog
Message 9 of 10
(2,995 Views)

Thanks Rolfk,

 

        That sounds like a definite option, but I am going to back burner that as an option for the moment.  I have spoken to Goepel and it seems that there is an alternate set of DLLs which use an API client and should fix the problem. 

 

  Thanks for your help,

 

        Ian

0 Kudos
Message 10 of 10
(2,933 Views)