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: 

Calling dll from any thread causes application crash

Solved!
Go to solution

I have an application built in labview 2015 that acquires spectra from 6 spectrometers via an external dll. The dll triggers a single event in labview when data is ready to be pulled from the spectrometers. From this event I run a non re-entrant sub vi that contains a function node to pull the data, which is set to run in any thread because it yields drastic performance improvements as apposed to running in the UI thread.

However this can cause the application to crash with a windows log message as follows:

Faulting application name: Axiom 2.0.exe, version: 1.0.0.82, time stamp: 0x5581a6b7
Faulting module name: lvrt.dll, version: 15.0.0.4024, time stamp: 0x5581ac03
Exception code: 0xc0000005
Fault offset: 0x0000000000bec7c0
Faulting process id: 0x15c0
Faulting application start time: 0x01d11e6face9febd
Faulting application path: C:\Axiom LA 2.0\builds\Axiom 2.0\Axiom 2.0.exe
Faulting module path: C:\Program Files\National Instruments\Shared\LabVIEW Run-Time\2015\lvrt.dll
Report Id: 7d4ef3a8-8a91-11e5-94e9-90b11c894ef8

 

I am not sure if the dll is so called thread safe or not. Also I don't understand how this is causing a problem anyways since this is the only node that is accessing the dll at that time and each of the 6 spectrometers are polled sequentially?

Is there anyway I can still reap the benefits that calling the dll from any thread provides without causing my application to crash.

An example of the performance increase is that I can poll the 6 spectrometer at 70-80Hz when set to run in any thread as apposed to a mere 10Hz when set to Run in UI thread.

 

Thanks

0 Kudos
Message 1 of 3
(3,949 Views)
Solution
Accepted by topic author Jimmy01

Jimmy01 wrote:

I am not sure if the dll is so called thread safe or not. Also I don't understand how this is causing a problem anyways since this is the only node that is accessing the dll at that time and each of the 6 spectrometers are polled sequentially?

Is there anyway I can still reap the benefits that calling the dll from any thread provides without causing my application to crash.


Sounds like the DLL is not thread-safe. If you don't run in the UI thread, there's no guarantee that the DLL will always be called from the same thread, even if you only call it in one non-reentrant subVI. By default LabVIEW allocates multiple threads per execution system, except for the UI. If the DLL stores some information from one call to the next, that context may be lost when run in a different thread.

 

Here's a thread that provides two possible solutions; one requires a wrapper DLL, the other uses the "threadconfig" utility (or corresponding INI file settings) to force one execution subsystem to a single thread http://forums.ni.com/t5/LabVIEW/Force-DLLs-to-tun-in-the-same-thread-expect-the-UI-Thread/td-p/11438...

Another option would be to put the call to the DLL in a timed loop that runs constantly, and you could use a queue or notifier to pass data in and out. A timed loop runs in a single dedicated thread, so I think this will work.

0 Kudos
Message 2 of 3
(3,934 Views)

Thanks for your response nathand, I will try some of those solutions out.

0 Kudos
Message 3 of 3
(3,920 Views)