Forum > FPC development
The time in Sleep is wrong, + 1
zanden30@hetnet.nl:
The implementation on Sleep ( t ) , t [mS] is wrong.
t = 0 gives 0 mS sleep. OK.
But any other value gives (t + 1) mS of sleep.
Hence, it is impossible to Sleep 1 mS.
By the way: on Windows 10 the sleep time is on average far within 5% precise, much better than suggested in the documentation. Not too bad……
tr_escape:
I tested in windows 10 Lazarus 1.9.0 rFRET_UNKNOWN_REVISION FPC 3.1.1 i386-win32-win32/win64
By the code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;uses SysUtils;var first,last : TDateTime;begin first:=Now; Sleep(1); last:=Now; WriteLn('Between : '+FormatDateTime('hh:nn:ss.zzz',last-first)); ReadLn; end.
It is gives 00:00:00.001 or 00:00:00.002, I think it is up to OS busyness time.
marcov:
So what OS is this?
Afaik Sleep(x) sleeps AT LEAST x ms. Then it might take another context switch to activate the thread and get it running. Such latencies are often CPU dependent.
440bx:
--- Quote from: marcov on November 22, 2018, 11:48:31 am ---So what OS is this?
Afaik Sleep(x) sleeps AT LEAST x ms. Then it might take another context switch to activate the thread and get it running. Such latencies are often CPU dependent.
--- End quote ---
Not to mention highly OS dependent.
Thaddy:
T=0 is a special case on windows and means "give up timeslice". See msdn https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-sleep
And indeed, it is highly platform dependent. It requires a RTOS to reliably get the exact value.
Navigation
[0] Message Index
[#] Next page