[fpc-devel] daemonapp 100% cpu easting fix
Alvise Nicoletti
alvise.nicoletti at siteland.it
Mon Nov 19 12:35:00 CET 2007
Steve Howe ha scritto:
> 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.
>
>
Don't know if that helps, but can this problem be related to the
"strange behaviour" I notifyed in this mailing list with the topic:
"[lazarus] [fpc] strange behaviour (crash) in a closing linux daemon"
the 07/11/2007
?
More information about the fpc-devel
mailing list