Article View: borland.public.cppbuilder.nativeapi
Article #2307Re: VC++ CSemaphore equivalent?
From: Dennis Jones
Date: Mon, 12 Mar 2007 16:29
Date: Mon, 12 Mar 2007 16:29
75 lines
3494 bytes
3494 bytes
"Robert G. Hoover" <not.a.real.address@anywhere.sorry> wrote in message
news:45f57403@newsgroups.borland.com...
> Hi,
>
> I've written a video streaming application in Borland C++ Builder
> v5,6,2006 that
> is experiencing a drastic performance decline on the new Intel D 935 (dual
> core)
> processor. My camera supplier recommended using the Micro$oft CSemaphore
> classes
> which is impractical as I use Borland products exclusively to develop my
> code.
> Is there a Borland equivalent? Can I use the CreateSemaphore(),
> OpenSemaphore(),
> ReleaseSemaphore() to keep my video grab/display thread from hiccuping so
> badly?
> For reference, I have appended my thread code which uses simple bool
> variables.
> If I utilize this Sleep() command at the bottom of the loop, performance
> is
> improved, though not like it was on older machines. My 4-year-old laptop
> is
> outperforming my tricked-out desktop!!! Any advice is welcome!
>
> Thanks so much!
>
> Rob
>
> _________________________________________________________________________________
>
> // 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 semiphore
> busy = true;
>
> // grab video frame(s) from camera
> Grab(live_grabbing_count);
>
> // process image data
> Process();
>
> // display current image on screen
> Display();
>
> // clear semiphore
> busy = false;
>
> // preserve process time
> // Sleep(FrameRateTimeOut);
> }
> }
First, your code doesn't really give enough information to go on -- it
doesn't show where the 'busy' flag is being tested, and doesn't provide any
context to make sense of the problem you are having. You should probably
post a more complete example.
Second, if a Semaphore is needed, you can of course use the Win32 Semaphore
functions (CSemaphore is merely a wrapper around those functions), or you
can write your own semaphore class/wrapper.
Third, do you really need a semaphore? Semaphores are typically used for
resource counting. If you just need to synchronize access to data, a
critical section is simpler and faster.
- Dennis
Technical Details
Message-ID:
<45f57fd5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45f57403@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,411b13b57e2ea81a X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Dennis Jones" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <45f57403@newsgroups.borland.com> Subject: Re: VC++ CSemaphore equivalent? Date: Mon, 12 Mar 2007 09:29:54 -0700 Lines: 77 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 71.245.109.58 Message-ID: <45f57fd5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1173716949 71.245.109.58 (12 Mar 2007 09:29:09 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail