LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CmtWaitForThreadPoolFunctionCompletion Problems

Solved!
Go to solution

I'm having some problems with the Cmt functions, and I feel like I'm doing everything correctly, but for whatever reason when debug my program whenever it ends I'm prompted with a runtime error that says something like:

 

"Unknown source position, thread id 0x000000C3

 

There are threads on the RT target that are still running or have previously run CVI code.

 

Please verify that your application cleans up all of its threads. Threads left running are bad."

 

Thats paraphrasing, but it's kind of a half hearted runtime error because it leaves the possibility that the threads aren't running anymore.

 

To start a thread I call: CmtScheduleThreadPoolFunction

When the thread returns I use this statement: return CmtExitThreadPoolThread(0); (I've also tried just returning 0)

Before exiting the program from the main thread I call: CmtWaitForThreadPoolFunctionCompletion

Then: CmtReleaseThreadPoolFunctionID

 

I get no runtime errors until the program ends (with the error above). I've tried commenting out the while loop in the thread call back function so it only runs once then returns, wait several seconds, then called the wait for completion and release ID functions. Is there something I'm forgetting to do? Is my thread really running still or is this an error that always comes up when you use threads? Is there something I can do to verify my thread isn't running?

 

Thanks,

Kevin

 

 

0 Kudos
Message 1 of 4
(3,313 Views)

OK, I also just tried calling CmtGetThreadPoolFunctionAttribute after the wait for completion function and I get a status of 4 (execution complete). So it seems like to me that everything is good. So I guess I should just ignore this run-time error?

 

Thanks,

Kevin

0 Kudos
Message 2 of 4
(3,311 Views)
Solution
Accepted by topic author kevin.key

Hey Kevin - 

 

Just curious - are you using the DEFAULT_THREAD_POOL? This could be the cause of the error you're describing.  If you are, take a look at the documentation for CmtScheduleThreadPoolFunction - specifically the RT note for the first parameter.  DEFAULT_THREAD_POOL threads never exit, and so result in the error you're seeing.  On RT, you must create your own threadpool.

 

NickB

National Instruments

Message 3 of 4
(3,299 Views)

That was it. Thanks. I guess I never stumbled on that documentation for the DEFAULT_THREAD_POOL. I created my own thread pool and no more error.

 

Kevin

0 Kudos
Message 4 of 4
(3,295 Views)