Article View: borland.public.cppbuilder.nativeapi
Article #11487Re: TTimers and Critical Sections...
From: Remy Lebeau (TeamB)
Date: Thu, 05 Feb 2004 23:53
Date: Thu, 05 Feb 2004 23:53
47 lines
2902 bytes
2902 bytes
"Mike Collins" <mikec@kr8.co.uk> wrote in message news:4022d173$1@newsgroups.borland.com... > What is the situation if I enter a Critical Section within > the OnTimer event of TTimer? Are there other threads involved also using the same critical section? If not, then it has no effect at all. > As it stands, this all happens under the OnTimer event. > There is also the main thread of the application <snip> If you are using TTimer on a form, then OnTimer is executed in the context of the main thread. TTimer is not a multi-threaded timer. It posts WM_TIMER messages to the owning thread's message queue. > 1) The TTimer thread <snip> Are you saying that you are actually using a separate worker thread that is using TTimer internally? If so, then why are you using TTimer at all? Why just just loop the thread with a Sleep() after each iteration? Even better would be if the hardware sends out any kind of notification when actual data is available, then you dn't have to poll at all. > 2) The TTimer thread could be tired up decoding and thus > fire a second time or third etc. Disable the timer when you first enter the handler, and then reenable the timer when you are finished. > However I don't really understand what will happen with > the timer if the event fires a second or third time. The timer is blocked while its OnTimer event code is running. If the main thread has the critical section locked, and you really are using the TTimer in a separate worker thread (which you shouldn't really need to do), then the timer is blocked until the main thread releases the critical section. Which is why you should not keep the critical section locked for any great length of time. If all you are doing is fill a structure and read the structure back, then keep the critical section use to a minimum, locking at the last possible moment and then releasing it as soon as possible. Gambit
Technical Details
Message-ID:
<4022d5b0$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4022d173$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,e86366b203b792f7 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-02-05 16:11:03 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4022d173$1@newsgroups.borland.com> Subject: Re: TTimers and Critical Sections... Date: Thu, 5 Feb 2004 15:53:09 -0800 Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <4022d5b0$2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1076024752 67.22.138.253 (5 Feb 2004 15:45:52 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail