[prev in list] [next in list] [prev in thread] [next in thread]
List: cygwin
Subject: Re: does usleep() sleep more than it's supposed to?
From: Brian Ford <Brian.Ford () FlightSafety ! com>
Date: 2007-02-26 15:29:46
Message-ID: Pine.CYG.4.58.0702260916320.1712 () PC1163-8460-XP ! flightsafety ! com
[Download RAW message or body]
On Mon, 26 Feb 2007, Carlo Florendo wrote:
> I'm writing an application that requires time precisions up to the
> microsecond level.
Then you shouldn't be using Windows. Millisecond resolution is all the
scheduler can do (this varies slightly depending on the platform).
> However, I put a hard-coded adjustment of 9000 microseconds since
> usleep() seems to sleep on the average of 9000 microseconds more than
> it's supposed to, at least on my system.
Follow this thread for history and discussion:
http://sourceware.org/ml/cygwin-developers/2005-11/msg00000.html
Put this in its own (separate from all Cygwin code) object file, call
it before any timing calls in your application, and link it with -lwinmm:
#include "windows.h"
void
SetSchedulerMaxRes(void)
{
TIMECAPS tc;
/* Set the system scheduler resolution to its maximum.
* Needed for Cygwin >= 1.5.20, broken in 1.5.19, and unnecessary
* <= 1.5.18 because it was always done by Cygwin. Required for */
if (timeGetDevCaps(&tc, sizeof(tc)) != TIMERR_NOERROR)
{
printf("timeGetDevCaps error %d\n", GetLastError());
tc.wPeriodMin = 1; /* Try 1 ms and hope for the best */
}
if (timeBeginPeriod(tc.wPeriodMin) != TIMERR_NOERROR)
printf("timeBeginPeriod error %d\n", GetLastError());
}
--
Brian Ford
Lead Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained crew...
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic