Sleep(30) is not reliable?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Sleep(30) is not reliable?

AlexeyT
In Lazarus component EControl I call Sleep(30) to wait when timer tick
work is done.

while FBusy do Sleep(30);

and app loops forever now in sleep().

procedure Sleep(milliseconds: Cardinal);
Var
   timeout,timeoutresult : TTimespec;
   res: cint;
begin
   timeout.tv_sec:=milliseconds div 1000;
   timeout.tv_nsec:=1000*1000*(milliseconds mod 1000);
   repeat
     res:=fpnanosleep(@timeout,@timeoutresult);
     timeout:=timeoutresult;
   until (res<>-1) or (fpgeterrno<>ESysEINTR);
end;

It is fpc 3.0.2. IDE Lazarus shows long loop inside this 'repeat'. i
waited 10-20seconds.


--
Regards,
Alexey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sleep(30) is not reliable?

AlexeyT
Details:
Ubuntu 17.4 x64; Lazarus 1.9 trunk, fpc 3.0.2.
I see IDE call stack like this  when i pause app (during loop forever)

SYSTEM_$$_FPSYSCALL$INT64$INT64$$INT64
000000000041E7E0 55                       push   %rbp
000000000041E7E1 4889e5                   mov    %rsp,%rbp
000000000041E7E4 488d6424f0               lea    -0x10(%rsp),%rsp
000000000041E7E9 4889f8                   mov    %rdi,%rax
000000000041E7EC 4889f7                   mov    %rsi,%rdi
000000000041E7EF 0f05                     syscall
000000000041E7F1 483d01f0ffff             cmp $0xfffffffffffff001,%rax
000000000041E7F7 7215                     jb     0x41e80e
<SYSTEM_$$_FPSYSCALL$INT64$INT64$$INT64+46>
000000000041E7F9 48f7d8                   neg    %rax
000000000041E7FC 4889c7                   mov    %rax,%rdi
000000000041E7FF e87cffffff               callq  0x41e780
<SYSTEM_$$_SETERRNO$LONGINT>
000000000041E804 48b8ffffffffffffffff     movabs $0xffffffffffffffff,%rax
000000000041E80E c9                       leaveq
000000000041E80F c3                       retq
SYSTEM_$$_FPSYSCALL$INT64$INT64$INT64$$INT64
000000000041E810 55                       push   %rbp
000000000041E811 4889e5                   mov    %rsp,%rbp
000000000041E814 488d6424f0               lea    -0x10(%rsp),%rsp
000000000041E819 4889f8                   mov    %rdi,%rax
000000000041E81C 4889f7                   mov    %rsi,%rdi
000000000041E81F 4889d6                   mov    %rdx,%rsi
000000000041E822 0f05                     syscall
000000000041E824 483d01f0ffff             cmp $0xfffffffffffff001,%rax
<<<<< here IDE stops

Alexey
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sleep(30) is not reliable?

Karoly Balogh (Charlie/SGR)
Hi,

On Wed, 24 Jan 2018, AlexeyT wrote:

> Details:
> Ubuntu 17.4 x64; Lazarus 1.9 trunk, fpc 3.0.2.
> I see IDE call stack like this  when i pause app (during loop forever)
>
Can you run strace on your app, to discover what are the nanosleep
syscalls entry values and what are the return values? That should reveal
if there's a flaw in that SysUtils sleep code loop.

But the other possibility would be that your code never sets FBusy to
false, if it calls Sleep() in a loop?

Charlie
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sleep(30) is not reliable?

Michael Van Canneyt
In reply to this post by AlexeyT


On Wed, 24 Jan 2018, AlexeyT wrote:

> In Lazarus component EControl I call Sleep(30) to wait when timer tick
> work is done.
>
> while FBusy do Sleep(30);

How is the FBusy set to false ?

You should add an Application.Processmesages in this loop, otherwise the
timer tick (or whatever event sets FBusy to false) will never happen ?.

while FBusy do
   begin
   Sleep(30);
   Application.ProcessMessages;
   end;

Michael.

>
> and app loops forever now in sleep().
>
> procedure Sleep(milliseconds: Cardinal);
> Var
>   timeout,timeoutresult : TTimespec;
>   res: cint;
> begin
>   timeout.tv_sec:=milliseconds div 1000;
>   timeout.tv_nsec:=1000*1000*(milliseconds mod 1000);
>   repeat
>     res:=fpnanosleep(@timeout,@timeoutresult);
>     timeout:=timeoutresult;
>   until (res<>-1) or (fpgeterrno<>ESysEINTR);
> end;
>
> It is fpc 3.0.2. IDE Lazarus shows long loop inside this 'repeat'. i
> waited 10-20seconds.
>
>
> --
> Regards,
> Alexey
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sleep(30) is not reliable?

Mark Morgan Lloyd-5
In reply to this post by AlexeyT
On 24/01/18 16:15, AlexeyT wrote:

> In Lazarus component EControl I call Sleep(30) to wait when timer tick
> work is done.
> while FBusy do Sleep(30);
> and app loops forever now in sleep().
> procedure Sleep(milliseconds: Cardinal);Var   timeout,timeoutresult :
> TTimespec;   res: cint;begin   timeout.tv_sec:=milliseconds div 1000;  
> timeout.tv_nsec:=1000*1000*(milliseconds mod 1000);   repeat    
> res:=fpnanosleep(@timeout,@timeoutresult);     timeout:=timeoutresult;  
> until (res<>-1) or (fpgeterrno<>ESysEINTR);end;
> It is fpc 3.0.2. IDE Lazarus shows long loop inside this 'repeat'. i
> waited 10-20seconds.

What happens if you put an Application.ProcessMessages in there?

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal