🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #15726

Re: how to sleep 10 milisecond

#15726
From: Vladimir Afanasyev
Date: Tue, 17 Jun 2003 10:06
44 lines
2329 bytes
Hi,

"Boguslaw Fries" <B.Fries@luca-online.de> wrote:
>Hello,
>I need a function, which sleeps my thread for 5 - 10 milisecond but not
>more!
>Standad function Sleep( 10 ) - in cfact sleeps my thread fo 30 milisecond
>
>Any suggestions?
>Boguslaw Fries

I suppose right way it is using multimedia timer.
If you want to have good precision you need to use 
1 (or) milisecond interval. So your error will be about 1
millisecond.
It means that in
timeSetEvent(
  UINT           uDelay,      
  UINT           uResolution, 
  LPTIMECALLBACK lpTimeProc,  
  DWORD_PTR      dwUser,      
  UINT           fuEvent      
);

uResolution must be 0 and uDelay must be 1.
After 10 interrupts you will have about 10 millisecond.

Next reference gives you some explanation:
http://www.microsoft.com/whdc/hwdev/platform/proc/mm-timer.mspx

In all cases when you want such precision control you need 
in the corresponded control for all your system/ It means 
that your application is main application on your PC and 
if you increase process and thread(s) priority up to high 
it helps you decide problems. 
SetThreadExecutionState function also can be usefull for it.

If you plan that your PC will be busy for another work your 
hopes about good precision will be groundless.

And in many case it is not bad that timer function works in 
another thread.
Vladimir.
Technical Details
Message-ID: <3eeee82d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ee8c0df@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,b6af681927951d13
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-06-17 03:13:48 PST
From: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Subject: Re: how to sleep 10 milisecond
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 62.244.14.114 62.244.14.114    
X-Forwarded-For: 192.168.0.147
References:  <3ee8c0df@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3eeee82d$1@newsgroups.borland.com>
Date: 17 Jun 2003 03:06:37 -0700
X-Trace: newsgroups.borland.com 1055844397 207.105.83.65 (17 Jun 2003 03:06:37 -0700)
Lines: 45
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail