Article View: comp.lang.pascal.delphi.misc
Article #484Re: timebeginperiod doesn't succeed
From: David Reeve
Date: Wed, 15 Jan 2003 01:27
Date: Wed, 15 Jan 2003 01:27
48 lines
3089 bytes
3089 bytes
JJ wrote: > > Dear all, > I'm trying to increase the timer resolution using the function > timebeginperiod but this doesn't succeed at all. The resolution > remains unchanged. I tested the following code : > > timebeginperiod(1); //This function returns Timerr_noerror > t1 := timegettime; > sleep(1); > t2 := timegettime; > timeendperiod(1); > > The difference beetween t2 and t1 remains always equivalent to 10; > I also tried the same type of program with C++Builer but it doesn't > succeed neither. > > I'm running under Windows XP and uses Delphi6. > > Any help will be appreciated > > JJ Sleep is a task scheduling component. A call to sleep, causes the calling thread to yield immediately AND be descheduled, and to remain descheduled for at least the time specified in the parameter you pass. Even if you set a small value for sleep, the OS will not get round to rescheduling it for at least one time slice, and, even then, it may not execute for perhaps a few more time slices depending upon what other tasks are running. For W98 where the time slice period is of the order of 20ms, and, whatever sleep period you use, you will see a typical jitter of some 50ms in a lightly loaded system. In W2K and XP, things are different. I assume the OS timeslice is smaller, and the scheduling seems to be handled more efficiently and less time jitter is encountered. Now, I suspect the multimedia timing functions get their precision by messing with the OS scheduling in the code between the call to timeBeginPeriod and timeEndPeriod. Maybe someone in the ng knows where this is documented? So what happens when you place a sleep within a multimedia timer section? It's anyones guess. My feeling is that you shouldn't use sleep in this way. Its a poor timer, slugs the main VCL thread if you use it there, but works brilliantly as an efficient means to control cpu consumption of slave threads. Dave
Technical Details
Message-ID:
<3E24B8ED.C0CCF629@powerup.com.au>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news-out.cwix.com!newsfeed.cwix.com!news1.optus.net.au!optus!snewsf0.syd.ops.aspac.uu.net!nnrp1.ozemail.com.au!53ab2750!not-for-mailReferences:
<1eab579d.0301140551.6cb1ead8@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1091e5,4a80d2b500b97ee5 X-Google-Attributes: gid1091e5,public X-Google-Thread: 10baee,4a80d2b500b97ee5 X-Google-Attributes: gid10baee,public X-Google-ArrivalTime: 2003-01-14 17:04:50 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news-out.cwix.com!newsfeed.cwix.com!news1.optus.net.au!optus!snewsf0.syd.ops.aspac.uu.net!nnrp1.ozemail.com.au!53ab2750!not-for-mail Message-ID: <3E24B8ED.C0CCF629@powerup.com.au> From: David Reeve <drscientific@powerup.com.au> X-Mailer: Mozilla 4.7 [en-gb] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.pascal.delphi.misc,borland.public.delphi.winapi Subject: Re: timebeginperiod doesn't succeed References: <1eab579d.0301140551.6cb1ead8@posting.google.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 48 Date: Wed, 15 Jan 2003 11:27:09 +1000 NNTP-Posting-Host: 63.12.146.15 X-Trace: nnrp1.ozemail.com.au 1042592689 63.12.146.15 (Wed, 15 Jan 2003 12:04:49 EST) NNTP-Posting-Date: Wed, 15 Jan 2003 12:04:49 EST