[fpc-devel] daemonapp 100% cpu easting fix
Steve Howe
howesteve at gmail.com
Sat Nov 17 13:12:30 CET 2007
Hello all,
While using the daemonapp.pp unit to code a daemon, I've found that
applications that it eat 100% of the CPU. After tracking and debugging, I've
found out that the problem is in the daemonapp's TDaemonThread.Execute()
method:
procedure TDaemonThread.Execute;
begin
If FDaemon.Start then
begin
FDaemon.Status:=csRunning;
StartServiceExecute;
if not FDaemon.Execute then
begin
While Not Terminated do
CheckControlMessage(True);
CheckControlMessage(False);
end;
end;
end;
The loop has no interval so it just consumes all free CPU. I think it should
be modified like this:
procedure TDaemonThread.Execute;
begin
If FDaemon.Start then
begin
FDaemon.Status:=csRunning;
StartServiceExecute;
if not FDaemon.Execute then
begin
While Not Terminated do
begin
CheckControlMessage(True);
Sleep(50);
end;
CheckControlMessage(False);
end;
end;
end;
Someone could argue that the damon's thread priority could be changed instead
to "idle", making the thread more cooperative, but since daemonapp.inc's
TDaemonController.Main() method also creates internally a TDaemonThread, and
that thread is not exposed, changing the daemon's thread wouldn't help
either.
Does anyone have a better solution or comments ? Should I submit a patch ? If
the changed is accepted and someone could do it for me, it would be even
better.
--
Best Regards,
Steve Howe
More information about the fpc-devel
mailing list