LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread is killed with CmtTerminateThreadPoolThread causes GPIB calls to hang.

In the application under development a thread is killed by using the function CmtTerminateThreadPoolThread after which a call to any GPIB related function causes the system to hang. Why? How can I remedy this?
0 Kudos
Message 1 of 4
(3,093 Views)
You can stop using CmtTerminateThreadPoolThread. Killing threads through this method is extremely risky and should only be used in extreme circumstances like an unresponsive thread or system shutdown. As it warns you on the function panel for this function, all sorts of hangs can be caused by killing threads since you have no idea what they are doing when you kill them. For example, if your thread is killed while accessing the hard drive or a GPIB device, you could lock out those resources causing hangs such as you are seeing.

You should shutdown your threads by signaling the thread with a flag or a message to shutdown and letting it exit its function normally. This is true in all multithreaded programming, not just in CVI. Killing threads is a risky th
ing to do, and should only be done in extreme circumstances.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 4
(3,093 Views)
Thank you Chris, the reason why CmtTerminateThreadPoolThread is used is because a suite of tests are being executed by the thread, any of which may hang the system. Thus, there is no way to get unresponsive tests and the associated thread to cooperatively exit under normal conditions. The only way to get control over the system is to kill the thread. The process of killing the thread works just fine. Its just that at any point afterwards GPIB is unresponsive.
0 Kudos
Message 3 of 4
(3,093 Views)
It sounds like your thread is hanging in a GPIB action, so it is locking out the driver which is failing when you come back and try to access it after the thread is killed. You are going to have to debug the thread that is hanging and find out where in the test it is, and try to find a way to properly shut it down or you will have to leave the thread running until you finish the application.

Chris
0 Kudos
Message 4 of 4
(3,093 Views)