Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-01

Sleep(30) is not reliable?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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 (fpgeterrnoESysEINTR);
end;

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

Regards, Alexey
AlexeyT
to 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

Karoly Balogh (Charlie/SGR
to AlexeyT

Hi,

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

Michael Van Canneyt
to AlexeyT: In Lazarus component EControl I call Sleep(30) to wait when timer tick work is done.…
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.

Show quoted text 27 lines
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 (fpgeterrnoESysEINTR); end; It is fpc 3.0.2. IDE Lazarus shows long loop inside this 'repeat'. i waited 10-20seconds. -- Regards, Alexey _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Mark Morgan Lloyd
to AlexeyT: In Lazarus component EControl I call Sleep(30) to wait when timer tick work is done.…
AlexeyT wrote 11 lines
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 (fpgeterrnoESysEINTR);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]