NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread start and stop in different test steps

I'm using VC++ writing a DLL for TestStand. I'm trying to start a thread in one test step and at a later test step close this thread. The thread start and stops as predicted. However when I do a "Unload all Modules" (ofcourse after the thread has safely ended) TestStand crashes with a -17502 error. Why? The crash occures after my DLL retrieves the DETACH message.
 
 
0 Kudos
Message 1 of 6
(3,583 Views)
thread,

please take a look into this thread if it helps to solve your issue.

regards,
Norbert B.
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 6
(3,564 Views)
Do you have code in dll main? If so what is it? How are you ensuring the thread is stopped before unloading the dll? Are you waiting on the thread handle? If your thread is still running when the dll is unloaded, that could cause a crash or error.

Message Edited by dug9000 on 02-03-2007 01:48 PM

Message Edited by dug9000 on 02-03-2007 01:48 PM

0 Kudos
Message 3 of 6
(3,556 Views)
Hi,

there is no code in DLLMain() and yes I'm absolutely certain that all threads have terminated, all thread handles are closed etc. 
0 Kudos
Message 4 of 6
(3,534 Views)
Closing thread handles does not terminate the threads. You need to WaitForSingleObject() on the thread handle before closing it in order to wait for the thread to complete.

-Doug
0 Kudos
Message 5 of 6
(3,527 Views)
If you post a code sample that shows the problem, I might be better able to determine the cause. At any rate, if you are already calling WaitForSingleObject on the thread handle after signalling the thread to exit in some way then there might be some other cause, however the fact that a crash occurs immediately after the dll is unloaded makes me think the thread might still be running (a crash after unload is exactly what would happen in this case). Another possibility is C++ objects at global scope. C++ objects at global scope have their destructors called during process detach. If you have objects declared at global scope you might want to take a look at what they do in their destructors. It's best to avoid declaring objects at global scope in a dll because what can be done in their constructors and destructors is limited the same as what can be done in dllmain.

Hope this helps,
-Doug
0 Kudos
Message 6 of 6
(3,517 Views)