LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithread troubleshooting

I have the following problem:
I have a PC which communicates via UDP to another PC. Both PCs have OS Windows2000 and are running CVI/Labwindows. And Both programms are using 12 threads at the same time for communication. The strange think is the following:
If I open 12 threads, most time 1 thread is disadvantaged to the others. The strange think is, when I only open 4 threads for communication, there is still 1 thread disadvantaged. And if it is only one thread, it is the one which work slowly. The only solution which might work, currently is to end all threads, close the threadpool and reinitialize all functions before using them. But this will cost a lot of performance and handling might be more difficult.

This time I start all threads at
the programm start and let them do nothing until they are getting used.

all threads are using the same function, which ist developped for UDP I/O They are getting information with that (void*)-Parameter.

Again, I can´t understand why always 11 of 12 threads or 4 of 5 threads seem to run "safe" and fast, but there is always a random one (not always the same!) which is boring....
The ThreadPool of course is big enough and I tried several PRIORITY-Settings for it.
Please help. Thanks.

Jefferson
0 Kudos
Message 1 of 5
(3,491 Views)
Jefferson,

Multithreaded applications are hard to troubleshoot, I have a couple of questions for you, what version of CVi are you using? are you using any type of data protection? do have a piece of code that we could see to replicate the problem?

I'm not aware of any known issue with multithreading performance issues, please keep me posted to work on this.

Regards,

Juan Carlos
N.I.
0 Kudos
Message 2 of 5
(3,491 Views)
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
0 Kudos
Message 3 of 5
(3,491 Views)
Oh sorry, Juan, I forgot:

I am using CVI LabWindows V6.0
OS: Windows 2000
Machine: 2.4 Ghz P4 with 512 MB RAM
0 Kudos
Message 4 of 5
(3,491 Views)
Jefferson,

I'll look into your code, in the mean time you can call our support line in Germany, you can use this link:

http://sine.ni.com/apps/we/niae_asc.main?lang=D

I'll let you know if there is anything that I can find.

Juan Carlos
N.I.
0 Kudos
Message 5 of 5
(3,491 Views)