delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/02/26/10:30:24

X-Spam-Check-By: sourceware.org
Date: Mon, 26 Feb 2007 09:29:46 -0600
From: Brian Ford <Brian DOT Ford AT FlightSafety DOT com>
Reply-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
Subject: Re: does usleep() sleep more than it's supposed to?
In-Reply-To: <45E292D6.30906@gmail.com>
Message-ID: <Pine.CYG.4.58.0702260916320.1712@PC1163-8460-XP.flightsafety.com>
References: <45E292D6 DOT 30906 AT gmail DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019