Hello Juan,
thanks for answering my thread 🙂
ok, I will write down the main lines here:
First, the declaration of the multithreading function:
int CVICALLBACK UDP_MASTER(void* ThreadNr);
Before calling the Multithreadfunction, I make my own threadpools and initialize them like this:
TStatus=CmtNewThreadPool (MAXTHREADS+1, &poolHandle);
TStatus=CmtNewThreadPool (1, &poolHandle2);
TStatus=CmtSetThreadPoolAttribute(poolHandle,ATTR_TP_PROCESS_EVENTS_WHILE_WAITING,1);
TStatus=CmtSetThreadPoolAttribute(poolHandle2,ATTR_TP_PROCESS_EVENTS_WHILE_WAITING,1);
TStatus=CmtSetThreadPoolAttribute(poolHandle,ATTR_TP_THREAD_SECURITY,0);
TStatus=CmtSetThreadPoolAttribute(poolHandle2,ATTR_TP_THREAD_SECURITY,0);
TStatus=CmtSetThreadPoolAttribute(poolHandle,ATTR_TP_THREAD_PRIORITY,THREAD_PRIORITY_NORMAL);
TStatus=CmtSetThreadPoolAttribute(poolHandle2,ATTR_TP_THREAD_PRIORITY,THREAD_PRIORITY_BELOW_NORMAL);
So I have 2 Threadpools open, one is about 12 threads, and the other one is only 1 thread.
The Argument for the UDP_MASTER-Function is a array of a strucure, in which I specify the threads own parameters.
This function is called 12 times so I have 12 threads using the same function. Every thread is handling UDP I/O, but my current problem occurs even, if I drop off the complete source code in it.
Here the definition of the UDP_MASTER-Threadfunction:
int CVICALLBACK UDP_MASTER(void* ThreadNr)
{
SetSleepPolicy(VAL_SLEEP_NONE);
ProcessSystemEvents();
/* do some magic */
Running[(int)ThreadNr]=0; // Show thread is ready
return(0);
}
I killed everything "magic" in the function to see what happens, but there still occurs the same problem
I currently call those functions with a CVI-timer, due to have better systemperformance, and less CPU-Usage instead of endless-loops.
Here the (complete) timer-Call code:
int CVICALLBACK TestTimerCB (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
int x=0;
switch (event)
{
case EVENT_TIMER_TICK:
for(x=0;x<=11;x++)
{
if(Running[x]>0)// See if the thread still runs
{
CmtWaitForThreadPoolFunctionCompletion
(poolHandle,ThreadID[x],0); // wait if
// thread runs out.
}
CmtReleaseThreadPoolFunctionIDpoolHandle,ThreadID[x]); //Dropping Thread ID
Running[x]=0; // Flag for show Thread is ready
else
{
CmtScheduleThreadPoolFunction
(poolHandle,UDP_MASTER,(void*)x,&ThreadID[x]);
}
Running[x]=1; // set Flag Thread is started
} // end for()
}
break;
}
return(0);
}
Now the Troubleshoot: if I run my programm, it runs nice for about 1 minute, after that, the CPU-Usage becomes alomst zero and the programm seems to sleep.
I have no memory leak coz I always watch carefully the memory and cpu usage of the Programm.
Thanks for any help! Maybe there is a german supportline, too, which I can call?
Best reguards,
Jefferson