Re: Best option for 'idle wait'

From: poltrone (nospam_at_nospam.net)
Date: 07/29/04


Date: Thu, 29 Jul 2004 09:06:00 +0200

AFAIK there is only one mechanism in windows, that lets you time operations
with a higher resolution than several milliseconds (without busy waiting)
and that's the multimedia timer (timeSetEvent()). But such a timer doesn't
block one of your threads, but creates a new one, which in turn will call
a function that you supply after some time. Maybe you can change your code
to work that way.

Ciao,
poltrone

"Harshal" <mumbaiyaa@yahoo.com> schrieb im Newsbeitrag
news:9f8e33a7.0407281300.da1ca8f@posting.google.com...
> Hello,
>
> I am trying to find the best way to wait for a specific time-period
> inside a loop. I want to wait for some time between each execution of
> the loop. The problem is that the wait period is less than 1
> millisecond (typically a few hundred micro-seconds) and so I can't
> depend on Sleep() or even on waitable timers. I am currently using a
> 'for' loop as a delay loop but this 'busy wait' consumes a lot of CPU
> cycles and I can't do much else while I am waiting. Are there other
> ways of waiting for sub-millisecond periods?
>
> I know that Windows is not a real-time OS so I won't be able to get
> very accurate microsecond-level timing. But I would settle for a
> variation of tens of microseconds if I could do it without tying up
> the CPU.
>
> Thanks for any pointers.
>
> Regards,
> Harshal



Relevant Pages

  • Re: How does timer work?
    ... The main difference is that the former uses, behind the scenes, the unmanaged WM_TIMER functionality in Windows, causing timing events to be raised on the main UI thread. ... I mean what is happening when the procedure raised on the tick event takes longer or shorter time. ... Threads always get to finish their tiemslice if they want to, and so for short timer intervals that are roughly the same or shorter than the length of a timeslice in Windows (generally tens of milliseconds), there can be significant delays beyond the requested interval. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: timers
    ... In this particular example I am setting a timer to go off every 25 ... milliseconds it goes off every 31 milliseconds. ... "In Windows 98, the timer has the same 55-msec resolution as the underlying ... is 18.207 clock ticks, which is rounded down to 18 clock ticks, which is ...
    (microsoft.public.vc.mfc)
  • Re: c# Timer -- .NET performance counters on this system are corrupt
    ... "The Windows Forms Timer component is single-threaded, ... to an accuracy of 55 milliseconds. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: SMTPSVC repeatedly times out along with RESvc, IISADMIN, and W
    ... Timeout (30000 milliseconds) waiting for a transaction response from the ...
    (microsoft.public.windows.server.sbs)
  • Re: Weird 2003 SBS Server Timeouts (30000 milliseconds) waiting for a transaction response
    ... > 1) Timeout (30000 milliseconds) waiting for a transaction response from ...
    (microsoft.public.windows.server.general)

Loading