Project

General

Profile

Actions

Feature #3587

closed

windows: unable to sleep < 0.015s

Added by rogerdpack (Roger Pack) over 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:31353]

Description

=begin

sleep 0.0001; Hitimes::Interval.measure { 2.times { sleep 0.000001}}
=> 0.03124279761813303

(it's always 0.03s)
This surprised me a bit, since it differed from Linux behavior.
Thanks!
=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #2637: unable to select for < 0.1s in windowsClosedusa (Usaku NAKAMURA)01/24/2010Actions
Actions #1

Updated by kosaki (Motohiro KOSAKI) over 13 years ago

=begin
Hi

2010/7/19 Roger Pack :

Bug #3587: windows: unable to sleep < 0.015s
http://redmine.ruby-lang.org/issues/show/3587

Author: Roger Pack
Status: Open, Priority: Normal
ruby -v: ruby 1.9.3dev (2010-07-19 trunk 28684) [i386-mingw32]

sleep 0.0001; Hitimes::Interval.measure { 2.times { sleep 0.000001}}
=> 0.03124279761813303

(it's always 0.03s)
This surprised me a bit, since it differed from Linux behavior.
Thanks!

Typically, windows has 1/64sec (15.625ms) tick resolution. but linux has
1/1000sec tick resolution. So, I don't surprised this so much.

Do you have any improvement idea?

=end

Actions #2

Updated by raggi (James Tucker) over 13 years ago

=begin

On 19 Jul 2010, at 16:19, KOSAKI Motohiro wrote:

Hi

2010/7/19 Roger Pack :

Bug #3587: windows: unable to sleep < 0.015s
http://redmine.ruby-lang.org/issues/show/3587

Author: Roger Pack
Status: Open, Priority: Normal
ruby -v: ruby 1.9.3dev (2010-07-19 trunk 28684) [i386-mingw32]

sleep 0.0001; Hitimes::Interval.measure { 2.times { sleep 0.000001}}
=> 0.03124279761813303

(it's always 0.03s)
This surprised me a bit, since it differed from Linux behavior.
Thanks!

Typically, windows has 1/64sec (15.625ms) tick resolution. but linux has
1/1000sec tick resolution. So, I don't surprised this so much.

Do you have any improvement idea?

I am told there is a better way to do this (iirc, some media api), but, this is aged code I have for it:

#include "stdafx.h"
#include <Windows.h>
typedef LONG NTSTATUS;
typedef NTSTATUS (__stdcall *NSTR)(ULONG, BOOLEAN, PULONG);
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
BOOL NtSetTimerResolution
(
IN ULONG RequestedResolution,
IN BOOLEAN Set,
OUT PULONG ActualResolution
);

int _tmain(int argc, _TCHAR* argv[])
{
HMODULE hNtDll = ::LoadLibrary(_T("ntdll.dll"));
BOOL fRetVal = FALSE;
ULONG RequestedResolution = 10000, ActualResolution = 0;
BOOL Set = true;
if (hNtDll)
{
NSTR pNSTR = (NSTR)::GetProcAddress(hNtDll, "NtSetTimerResolution");
if (pNSTR)
{
NTSTATUS nts = (*pNSTR)(RequestedResolution, Set, &ActualResolution);
if (STATUS_SUCCESS == nts)
while (true)
Sleep(100000);
else
return 1;
}
}
}

If the API is restricted by timer resolution, this code running as an application on the system should open that up to 1ms, other methods for doing this include running flash or opening media player.

I believe there are ways to do better, but I had another purpose for this code running as a service.

Roger - if this helps, I can provide a patch to hitimes, let me know.

=end

Actions #3

Updated by nobu (Nobuyoshi Nakada) over 13 years ago

  • Priority changed from Normal to 3

=begin

=end

Actions #4

Updated by rogerdpack (Roger Pack) over 13 years ago

  • Status changed from Open to Closed

=begin
This isn't a problem on windows 7, so...unless there's an easier way to do this in windows (or interest from any one else but myself), closing for now.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0