Article View: borland.public.cppbuilder.nativeapi
Article #1987Re: Multi-Thread HDC and Video Display
From: Robert G. Hoover
Date: Fri, 25 May 2007 12:05
Date: Fri, 25 May 2007 12:05
81 lines
3634 bytes
3634 bytes
Hi Gents,
Thanks for the info.
Essentially I've got my main program doing what windows programs do... written
in BDS2006 C++, it displays menus, buttons, etc. and waits for user interaction
with the main message loop (managed for me by Borland). I also have a seperate
thread executed by...
// spawn thread for advanced grab/display routines
hThread = (HANDLE)BeginThread(THREAD_PRIORITY_NORMAL, 0,
VideoGrabbingThread, this, 0, ThreadID);
// set thread priority
SetThreadPriority(hThread, THREAD_PRIORITY_LOWEST);
...which in turn executes this...
// set semaphores
terminated = false;
busy = false;
grabbing = true;
// grab, process, display live video as normal
while (!terminated)
{
// give primary thread time to process frozen image
if (frozen)
Sleep(100);
// grab, process, and display video data
else
{
// set semaphore
busy = true;
// grab video frame(s) from camera
Grab(live_grabbing_count);
// process image data
// Process();
// display current image on screen
Display();
// clear semaphore
busy = false;
}
}
// allow main process to continue after terminating video loop
grabbing = false;
...Process() usually performs image processing stuff, byte by byte through the
Bitmap data. I manage all this myself without using any Windows API. Everything
is done with a unsigned char pointer in a buffer allocated by me. However, I
commented this routine out a while back and forgot to re-enable it. So, it's not
been active during my diagnosis.
So in general, 1 thread (my main app) processes event messages and 1 thread (my
own creation) grabs a video frame from the camera into a BITMAP buffer and
paints it on the screen using SetDIBits or StretchDIBits.
My problem is hard to diagnose. My symptoms are general slowness of video
refresh/update, reduced frame rate, OS crashes (blue DOS screen as "auto
restart" is disabled) with messages like IRQL_LESS_OR_EQUAL or BAD_POOL_HEADER.
A complicating factor to this is that the GUI updates in response to user
interaction. This is for a robotics app. So, when motors move, their absolute
positions are displayed immediately thru TLabel::Repaint(). I've surrounded
calls to the GUI with try/catch blocks. Is it possible this is related to my
problem? Perhaps if I configure my entire program to use a single side of the
processor then it will behave like it does on single-core machines? Can I do that?
Thank you for your assistance...
Rob
Technical Details
Message-ID:
<4656d0f8@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45f57403@newsgroups.borland.com> <4655cb92@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,411b13b57e2ea81a X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 25 May 2007 08:05:08 -0400 From: "Robert G. Hoover" <not.a.real.address@anywhere.sorry> User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Multi-Thread HDC and Video Display References: <45f57403@newsgroups.borland.com> <4655cb92@newsgroups.borland.com> In-Reply-To: <4655cb92@newsgroups.borland.com> X-Enigmail-Version: 0.94.1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 000743-4, 05/24/2007), Outbound message X-Antivirus-Status: Not-Tested NNTP-Posting-Host: 76.106.54.160 Message-ID: <4656d0f8@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1180094712 76.106.54.160 (25 May 2007 05:05:12 -0700) Lines: 81 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail