LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

system resources used out and crash in thread.

Same crash happened in CVI5.0 or CVI5.5 in Win98. Crash here means
the computer stops responding to any user input and I have to
press CTRL+ALT+DEL or restart PC.,
My program talks to a device through Parallel Port, so it's of no
big use sending the original code. I 'll try to describe the problem
as clear as I can.

I create a thread by CreateThread() and call a lot of function from
several DLLs in the thread. Normally the system resources is about
65% free. When the thread is started, free system resources reduced
dramatically to very low in less than half a minute until the whole
system stops responding.

The code is something like below:
* In CallFunc() I call functions from libraries and do a lot of
I/O.

// -------------------- Code Begin ---------------------------- //
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread_Loop,0,0,&ThreadID);

DWORD WINAPI Thread_Loop(LPVOID lpParam)
{
do{
// also tried CallFunc(1),CallFunc(2)...
CallFunc(7);
// add Delay here make things a little better, which means it
// can run for more times and then crash 🙂
Delay(0.5);
}while(!StopLoop);
}
// ---------------------- Code End ------------------------ //

When CallFunc() is called for about 11 times, it crashes.
And I tried other ways:

// -------------------- Code Begin ---------------------------- //
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread_Loop,0,0,&ThreadID);

DWORD WINAPI Thread_Loop(LPVOID lpParam)
{
CallFunc(1);
CallFunc(2);
CallFunc(3);
CallFunc(4);
CallFunc(5);
CallFunc(6);
CallFunc(7);
CallFunc(8);
CallFunc(9);
CallFunc(10);
CallFunc(11);
CallFunc(12);
}
// ---------------------- Code End ------------------------
//

When the thread comes to CallFunc(8) or so, it crashes.

The situation seems like resources such as memory not properly used
an released in the CallFunc(). But if I use CallFunc() directly,
not in thread, crash never happens.
0 Kudos
Message 1 of 2
(3,004 Views)
Hello

I havnt really seen anything like this one before. So what happens if you just place this function in a for loop without making another thread out of it. Also, have to tried placing this function ( or something similar ) in one of the CVI multithreading example programs and see if the same thing occurs? Are there any resources that are not being released in your function (device references, malloc'ed memory ..) ? What kind of resources are being used ? How are you monitoring the process? Here is a nice tool that helps you will real time task monitoring. Perhaps it might help in narrowing down the problem.

If you still cant find out why this is happening, you should contact one of our support engineers at ni.c
om/ask with the information you have.

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 2
(3,004 Views)