12-30-2014 12:14 PM - edited 12-30-2014 12:15 PM
Hello.
I want to launch some functions in different threads. Every function finish executing before the next one starts.
Each of these functions are launching through a single function pointer.
It does sound simple, but it is working only the first time. Afther that, I get an error (unfortunately I don't remember the error, something like "non debuggable program").
Here is the piece of code:
FuncPtrDouble = GetExternalModuleAddr(TestID, FuncName, &status);
if ( FuncPtrDouble != NULL)
{
//status = (*FuncPtrDouble)(&Result); //This one works everytime.
CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE, (*FuncPtrDouble)(&Result), NULL, &functionId); //Executes only once. Second time crushes.
CmtWaitForThreadPoolFunctionCompletion(DEFAULT_THREAD_POOL_HANDLE, functionId, 0);
CmtReleaseThreadPoolFunctionID(DEFAULT_THREAD_POOL_HANDLE, functionId);
}
12-31-2014 01:30 AM - edited 12-31-2014 01:32 AM
Actually, I made a mistake.
It does not crash the second time but the first time. And here I have a question.
My initial impression was that, since this is a thread, it runs parallel with the main program.
Here, when we step in CmtScheduleThreadPoolFunction, the main program freezes!
After it executes, the program crashes in the CmtWaitForThreadPoolFunctionCompletion.
So, I have two questions:
1. Why doesn't the the new thread run in parallel with the main program?
2. Why does it crush in the CmtWaitForThreadPoolFunctionCompletion?
Help?
Thanks,
Vasileios.
12-31-2014 01:42 AM
Update.
Since I focus my problem in the specific function, I searched NI forums again and found this thread:
And, while I do not have an RT system (my cRIO runs embedded windows), I replaced the DEFAULT_THREAD_POOL with the RUN_IN_SCHEDULED_THREAD and it works now. I mean that it doesn't crash.
But it is still not running in parallel.
Any ideas just for problem number 2?
Thanks.
12-31-2014 04:36 AM
Never mind, solved it.
I had many problems but figured it out as soon as I read the NI functions guide.
RTFM!!!!