Forum > Other
unblocked Sleep() for all Platforms
Thaddy:
Why sleep(1)? Shouldn't it be sleep(0)?
rvk:
--- Quote from: Thaddy on August 28, 2022, 12:56:38 pm ---Why sleep(1)? Shouldn't it be sleep(0)?
--- End quote ---
Why should it he sleep(0).
With sleep(0) you only relinquish the current time slice. But maybe you want your program to wait a lot longer. Doing sleep(0) each time is waisting time for each cycle.
But it might have been better to use sleep(10) or sleep(50).
It would depend on your usecase for this new non-blocking sleep function.
KodeZwerg:
--- Quote from: rvk on August 28, 2022, 12:51:36 pm ---Btw GetTickCount64 is a Windows function but is recreated in FPC to be cross platform.
--- End quote ---
Ahhhh this i did not knew yet, i am very common with Windows Api calls but really didnt knew that FPC reintroduce it for others!!!
Thanks for that information!!!
KodeZwerg:
--- Quote from: rvk on August 28, 2022, 01:04:38 pm ---
--- Quote from: Thaddy on August 28, 2022, 12:56:38 pm ---Why sleep(1)? Shouldn't it be sleep(0)?
--- End quote ---
Why should it he sleep(0).
With sleep(0) you only relinquish the current time slice. But maybe you want your program to wait a lot longer. Doing sleep(0) each time is waisting time for each cycle.
But it might have been better to use sleep(10) or sleep(50).
It would depend on your usecase for this new non-blocking sleep function.
--- End quote ---
I do fully agree, RTL Sleep(50) i also use(if at all)
PascalDragon:
--- Quote from: KodeZwerg on August 27, 2022, 03:56:24 pm ---In Windows i do use this ->
--- 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";}};} ---procedure Sleep(const AMilliSeconds: DWORD);var Ret: DWORD; WaitTime: Int64; Timer: THandle;begin Timer := CreateWaitableTimer(nil, TRUE, nil); WaitTime := Round((AMilliSeconds / 1000) * -10000000); SetWaitableTimer(Timer, WaitTime, 0, nil, nil, FALSE); repeat Ret := MsgWaitForMultipleObjects(1, Timer, FALSE, INFINITE, QS_ALLINPUT); if (Ret <> (WAIT_OBJECT_0+1)) then Break; Application.ProcessMessages; until False; if (Ret <> WAIT_OBJECT_0) then CancelWaitableTimer(Timer); CloseHandle(Timer);end; to temporarily suspend the workflow without that my application freeze or i do waste CPU.
Since i do use pure Windows Api calls to achieve that, how can i do the same for other OS's?
--- End quote ---
You'll have to dig into each OS and widgetset you want to support to get a 1:1 equivalent of this, especially the QS_ALLINPUT. If you're happy with getting interrupted due to received signals (which does likely not contain messages posted to the widgetset's message queue) on *nix systems you can simply use what FPC uses for it's Sleep implementation on *nix (namely fpnanosleep) and handle an error of ESysEINTR accordingly.
Navigation
[0] Message Index
[*] Previous page