delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/02/26/20:22:36

X-Spam-Check-By: sourceware.org
Message-ID: <45E387C8.8050908@gmail.com>
Date: Tue, 27 Feb 2007 09:22:16 +0800
From: Carlo Florendo <subscribermail AT gmail DOT com>
User-Agent: Thunderbird 1.5.0.9 (Windows/20061207)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: [SOLVED] Re: does usleep() sleep more than it's supposed to?
References: <45E292D6 DOT 30906 AT gmail DOT com> <Pine DOT CYG DOT 4 DOT 58 DOT 0702260916320 DOT 1712 AT PC1163-8460-XP DOT flightsafety DOT com>
In-Reply-To: <Pine.CYG.4.58.0702260916320.1712@PC1163-8460-XP.flightsafety.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

Brian Ford wrote:
> 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());
> }
> 


Impressive.


I never knew about timeGetDevCaps nor timeBeginPeriod but this
improved the sleep time by making it accurate up to
1000 microseconds, which *is* the behavior I've been
looking for for weeks now.

Here's the new output on my box:

$ ./a.exe
Print elapsed time at every call to usleep()
Elapsed time (sec:microsec) 0:100000
Elapsed time (sec:microsec) 0:101000
Elapsed time (sec:microsec) 0:100000
Elapsed time (sec:microsec) 0:101000
Elapsed time (sec:microsec) 0:101000
Elapsed time (sec:microsec) 0:100000
Elapsed time (sec:microsec) 0:101000
Elapsed time (sec:microsec) 0:100000
Elapsed time (sec:microsec) 0:101000
Elapsed time (sec:microsec) 0:100000

Print elapsed after the loop()
Elapsed time (sec:microsec) 1:26000




Thank you very much.

Best Regards,

Carlo



-- 
Carlo Florendo
Softare Engineer/Network Co-Administrator
Astra Philippines Inc.
UP-Ayala Technopark, Diliman 1101, Quezon City
Philippines
http://www.astra.ph

Member of the Astra Group of Companies
5-3-11 Sekido, Tama City
Tokyo 206-0011, Japan
http://www.astra.co.jp

--
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