🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.deployment
Article #164

Re: THREAD with SERIAL COMM

#164
From: at
Date: Mon, 26 Sep 2005 19:08
63 lines
2874 bytes
Thank you, I have used the WaitForSingleObject function and
this works fine !!
Now my app is vefy fluid, after a small tune of the delay time
now the application is ok!

Thanks.
Fabio

J�rg Reithaar wrote:
> Hi
> 
> Your thread consumes too much resources because you requested it to do so.
> It checkes for incomming data at maximum speed....
> 
>     while ((!this->Terminated) && (objSerial->InstanceActive))
>     {
>        if (this->CanReceive) Synchronize(ReceiveData);
>     }
> 
> This makes your pc to become sslllooooooowwwww.
> 
> You have to add a "delay" into this loop.
> 
> // declare a variable as follows...
> 
> HANDLE hSemaphore;
> 
> // ...then add the following into the infinite loop
> 
> hSemaphore = CreateSemaphore( NULL, 0, 10, "X" );
> WaitForSingleObject( hSemaphore, 30 );
> 
> Resulting code:
> 
> while ((!this->Terminated) && (objSerial->InstanceActive))
> {
>    if (this->CanReceive) Synchronize(ReceiveData);
>    hSemaphore = CreateSemaphore( NULL, 0, 10, "X" );
>    WaitForSingleObject( hSemaphore, 30 );
>  }
> 
> Some explanation:
> 
> Windows is not preemptive. Task do not "suspend" automaticly to give others 
> a chance to execute in paralell.
> Thread programming is very near to system an should respect some rules to 
> execute smoothly.
> Do nothing more than absolutly necessary inside the threads EXECUTE routine.
> WaitForSingleObject consumes no time-resources because it realy suspends 
> execution for the time given.
> 30 in this case means 30 milliseconds. This time is a minimum. The systems 
> resumes not before the time given.
> 
> In gereral: Avoid to use endless loops inside the thread. Try to leave the 
> thread "sleeping" as much as possible.
> Just "kick" it on when you expect a delayed action.
> 
> Please let me know of your success
> 
> J�rg Reithaar
> Reithaar Elektronik GmbH
> 
> 
Technical Details
Message-ID: <433846ac$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43205bc7@newsgroups.borland.com> <4336d8cf$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f8e54,5fc7742ce46e9625
X-Google-Attributes: gidf8e54,public
X-Google-Language: ENGLISH,ASCII
Date: Mon, 26 Sep 2005 21:08:05 +0200
From: at <"fabio(at)"@techside.it>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.deployment
Subject: Re: THREAD with SERIAL COMM
References: <43205bc7@newsgroups.borland.com> <4336d8cf$1@newsgroups.borland.com>
In-Reply-To: <4336d8cf$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 82.50.185.114
Message-ID: <433846ac$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1127761580 82.50.185.114 (26 Sep 2005 12:06:20 -0700)
Lines: 63
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail