This is really a multi-part question which centers around the fact that I create a thread multiple times in my program (not simultaneously) and it runs to completion very quickly each time. When I exit the main program quite after running for a while I seem to get the
Thread has exited with code (0x0)
message for each time the thread was started.
This may not seem a huge deal, but I potentially run this chunk of code 20-30K times during the run of the program, so it is obviously saving lots of information somewhere. My intention was that the program would fire the thread, it would run, exit, all be freed and then it could run again.
I also think I may be approaching the problem incorrectly and am open to suggestions.
I have a robotic vision (stereo) system which has a rotational axis and the motor fires a camera trigger every degree of rotation. Two cameras are waiting for the trigger and the camera driver responds by calling a Callback function when an image is grabbed (both cameras grab at the same time).
The callback for the cameras calls CreateThread and the thread copies the image data, does some processing and stores the image data. I do this in a thread because it is necessary to turn the program loose to handle the next camera grab.
The call looks something like this:
MyHandle = CreateThread(NULL, NULL, ProcessImageThreadFunc, NULL, NULL, &(MyThreadID));
unsigned long __stdcall ProcessImageThreadFunc(void *pContext)
int cntr = 0;
int ndx = PathArray->mImageRingNdx;
while( ( PathArray->mImgGrabbed[ndx] != 3 ) && ( cntr < 2000000 ) )
GrabProc->mFirstImgGrabbed = 0;
GrabProc->CheckForLastImage( 0, ndx );
Some time later, when I have done all I need to do and the program exits, I get LOTS of
Thread (0x123) has exited with code (0x0)
messages. The (0x123) part is different for each line.
Am I not letting go of the MyHandle or MyThreadID properly or something?
Should I not be doing this with a thread?