Re: multi-threading fundementals?
Here are some details. I tried to simplify it as much as i could.
I have the main dialog (main thread) that initializes connection with
camera 1 and displays video from camera 1.
From onInitDialog() in main dialog, I initiate connection to camera 2
and spool thread 2. Thread 2 creates its own window. Simply creating
the trhead 2 window does not slow down camera 1 (unless I have onPaints
going on in trhead 2).
Then I initiate a global worker thread (thread 3) which has a while
loop that waits for a frame to arrive from camera 2. When a new frame
arrives (into global memory), thread 3 calles
CCamera2thread:UpdateBitmap() that uses the pointer to the global
memory to populate a bitmap and to BitBlt() it.
Camera 1 thread slows down while Camera 2 video gets displayed (assayed
using the internal windows clock).
Camera 1 thread does not slow down when an identical algorythm for
thread 2 is run in a separate application (manufacturer's software).
CCamera1::initializeCamera2();
pCamera2_Thread =
(CCamera2Thread*)AfxBeginThread(RUNTIME_CLASS(CCamera2Thread),0);//setting
priority to -1 is not acceptable
//CCamera2Thread class:
CCamera2Thread::InitInstance() {
pCamera2Window = new CCamera2Window(cwnd);
VERIFY(pCamera2Window->Create());
pCamera2Window->ShowWindow(SW_SHOW);
}
//CCamera2Window class:
CCamera2Thread::UpdateBitmap() {
// take pointer to global memory and fill a pre-existing bitmap
// BitBlt the bitmap to a static control in pCamera2window.
}
CCamera2Window::OnBnClickedStartVideo() {
//set camera 2 parameters, allocate global memory for camera 2
//start camera 2 video
video_running_flag = true;
GlobalThreadHandle = CreateThread(...,VideoThread,...);
}
//global VideoThread
DWORD WINAPI VideoThread(){
while(video_running_flag) {
GetMostRecentImage()
pCamera2Thread->pCamera2Window->Update_Bitmap();
}
}