02-22-2011 09:33 AM
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
Solved! Go to Solution.
02-22-2011 09:38 AM
02-22-2011 12:56 PM
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
02-22-2011 01:48 PM