NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread termination at sequence unload

I want to have a thread that is started with a step execution in the setup. This thread is supposed to be running as long as the sequence is loaded in TestStand. Thus I would like to end this thread in the DLLMain (DLL_ PROCESS_DETACH). How can I do this?
 
TestStand seems to delete the allocated stack associated with the thread, before I get the chance to do a proper cleanup of the thread.
 
Thanks for your help.
0 Kudos
Message 1 of 5
(3,204 Views)

Hello!

 

I am not sure what you are trying to achieve and how you current setup look like such as version of TestStand, which adapter you are using (do you call a LabVIEW VI that in turn calls a DLL or do you use the C/C++ adapter directly for an example), which programming environment you are using among other things.

Do you have any code in your DllMain function in the DLL_PROCESS_ATTACH and/or DLL_PROCESS_DETACH cases? Most of the functions you can include in these sections pertain to memory and thread management only and if you then would include functions performing other operations in the DLL_PROCESS_ATTACH and/or DLL_PROCESS_DETACH sections, applications making calls to the DLL might behave unpredictably.

Do not use the attach and detach sections to open, configure, or close various interfaces (GPIB, Serial Port). If you are using LabWINDOWS/CVI ‘CloseCVIRTE()’ is an exception to this rule. You can include this function in the detach section of DLLMain without any issues.

 

Regards,
Jimmie Adolph
Systems Engineering Manager, National Instruments Northern European Region

0 Kudos
Message 2 of 5
(3,185 Views)
I'm using TestStand 3.0 and the C/C++ DLL adapter. The code is written in C and the functions used in TestStand are exported in the DLL file.
 
The thread is started as a step and and acts in background while the tests perform. This thread is to be closed when unloading the sequence file. I thought I could use the DLL_PROCESS_DETACH message in the DllMain to trigger the cleanup of the thread when the sequence file is unloaded. But it seems as TestStand cleans the stack before giving the thread a chance to cleanup. Thus it sometimes results in a crash.
 
Another question is how big stack can TestStand handle? By default when building in MSVC the compiler builds for a stack size of 1 MB, and also using CreateThread() gives the possibilty to set the stack size. Hence it could be a stack overflow.
 
0 Kudos
Message 3 of 5
(3,179 Views)

Hello!

Please look at these links since they talk about similar issues:

DLL unload problem
http://forums.ni.com/ni/board/message?board.id=330&message.id=5537&requireLogin=False

How to get TS to release USB ownership when unload DLL step
http://forums.ni.com/ni/board/message?board.id=330&message.id=5835&requireLogin=False

When it comes to stack sizes I don't know, so hopefully someone else gan provide some insight!

Regards,
Jimmie Adolph
Systems Engineering Manager, National Instruments Northern European Region

0 Kudos
Message 4 of 5
(3,171 Views)
Hi Jimmie,
 
I don't have any problem with TestStand not unloading my DLL file. The problem seems to be that TS starts cleaning before I get the DLL_PROCESS_DETACH message.
 
You said in your previous post that I should try to avoid code in the DLL_PROCESS_DETACH. Where would you suggest my cleanup then? I don't want to close my thread at the end of every execution.
 
 
0 Kudos
Message 5 of 5
(3,164 Views)