Sign in Join

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

Mailing lists / lazarus / 2014-01

TFPTimer, Linux

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Antonio Fortuny

Hi Folks.

Following a Michael advice I changed a TTimer by an TFPTime component in a Linux daemon application but the latter doesn't work. There is the code snippet of the TFPTime OnTimer event:

procedure TDaemon1.ThreadControlTimerTimer(Sender: TObject);
var
   Res: Boolean;
begin
   // se r?veille toutes les 10 secondes pour v?rifier l'?tat du thread
   FLog.Add(9, '1++++', esError);
   try
     FLog.Add(9, '2++++', esError);
   except
     on E: Exception do begin
       FLog.Error(Format('>>+++ error on log control thread:%s',
[E.Message]));
       Res := False;
     end;
   end;
   FLog.Add(9, '3++++', esError);
   try

FLog.Add(9, '4++++', esError); <<------------- this line appears into the log file

     ThreadControlTimer.Enabled := False;
     FLog.Add(9, '5++++', esError);     <<======= this line is never reached
     Res := DoThreadControl;
     FLog.Add(9, '6++++', esError);
   except
     on E: Exception do begin
       FLog.Error(Format('>>+++ error on control thread:%s', [E.Message]));
       Res := False;
     end;
   end;
   if Res then begin
     FLog.Add(9, '7++++ True', esError);
     ThreadControlTimer.Enabled := True;
   end else begin
     FLog.Add(9, '8++++ False', esError);
   end;
end;

It looks like the Enabled property doesn't work and blocks the TFPTimer in some way. The event is fired on time, but only once and never more. I'dl be glad to know what happens.

Antonio.

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com

Reply by email

Michael Van Canneyt
to Antonio Fortuny
Antonio Fortuny wrote 50 lines
Hi Folks. Following a Michael advice I changed a TTimer by an TFPTime component in a Linux daemon application but the latter doesn't work. There is the code snippet of the TFPTime OnTimer event: procedure TDaemon1.ThreadControlTimerTimer(Sender: TObject); var Res: Boolean; begin // se r?veille toutes les 10 secondes pour v?rifier l'?tat du thread FLog.Add(9, '1++++', esError); try FLog.Add(9, '2++++', esError); except on E: Exception do begin FLog.Error(Format('>>+++ error on log control thread:%s', [E.Message])); Res := False; end; end; FLog.Add(9, '3++++', esError); try FLog.Add(9, '4++++', esError); <<------------- this line appears into the log file ThreadControlTimer.Enabled := False; FLog.Add(9, '5++++', esError); <<======= this line is never reached Res := DoThreadControl; FLog.Add(9, '6++++', esError); except on E: Exception do begin FLog.Error(Format('>>+++ error on control thread:%s', [E.Message])); Res := False; end; end; if Res then begin FLog.Add(9, '7++++ True', esError); ThreadControlTimer.Enabled := True; end else begin FLog.Add(9, '8++++ False', esError); end; end; It looks like the Enabled property doesn't work and blocks the TFPTimer in some way. The event is fired on time, but only once and never more. I'dl be glad to know what happens.

DaemonApp works using threads.

TFPTimer is not usable in threads other than the main thread.

Michael.

Reply by email

Antonio Fortuny
to Michael Van Canneyt
Show quoted text 8 lines
> It looks like the Enabled property doesn't work and blocks the > TFPTimer in some way. The event is fired on time, but only once and > never more. > I'dl be glad to know what happens. DaemonApp works using threads. TFPTimer is not usable in threads other than the main thread.

Got it. I'll try something else.

Thanks,

Antonio;
Show quoted text 9 lines
Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140115/c3501880/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: fdhdbhib.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140115/c3501880/attachment.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: cefaedcc.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140115/c3501880/attachment-0001.jpg>

Reply by email

Antonio Fortuny
to Michael Van Canneyt: DaemonApp works using threads. TFPTimer is not usable in threads other than the main…
DaemonApp works using threads. TFPTimer is not usable in threads other than the main thread.

Right. So I made my own Timer based on the TFPTimer. Almost the same code except that the Synchronize(@EventProc) disapeared in my code and the EventProc is called immediately.
Another little feature is that the high level enable disable sequences do not kill the thread: using a TEvent and some lines of cole solves this problem whithout requiqring lots of CPU processing time. Even in in the worst case the thread will respond within 500 ms Yes, I know, but what if more than one thread calls the same procedure ? Well, it is not even protected by a critical section because based on a single rule: one Timer one procedure, nothing less nothing more. As a consequence I consider that the event procedure is part of the Timer object but only a test GUI application, my timer runs perfect in a multi-threaded environment (one timer, one thread embedded into an object). My only little disappointment is that the timer precision goes from -5 to +5 ms. But this doesn't bother me as my timers deal with tens (and more hundreds) of ms. So I consider that this little error isn't worth writing of code to get rid of it. I don't think that the world will stop turning around itself because a lack of 5 ms.

Antonio;
Show quoted text 9 lines
Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com

Reply by email

Lukasz Sokol
to Antonio Fortuny
Antonio Fortuny wrote 25 lines
> DaemonApp works using threads. > > TFPTimer is not usable in threads other than the main thread. Right. So I made my own Timer based on the TFPTimer. Almost the same code except that the Synchronize(@EventProc) disapeared in my code and the EventProc is called immediately. Another little feature is that the high level enable disable sequences do not kill the thread: using a TEvent and some lines of cole solves this problem whithout requiqring lots of CPU processing time. Even in in the worst case the thread will respond within 500 ms Yes, I know, but what if more than one thread calls the same procedure ? Well, it is not even protected by a critical section because based on a single rule: one Timer one procedure, nothing less nothing more. As a consequence I consider that the event procedure is part of the Timer object but only a test GUI application, my timer runs perfect in a multi-threaded environment (one timer, one thread embedded into an object). My only little disappointment is that the timer precision goes from -5 to +5 ms. But this doesn't bother me as my timers deal with tens (and more hundreds) of ms. So I consider that this little error isn't worth writing of code to get rid of it. I don't think that the world will stop turning around itself because a lack of 5 ms. Antonio;

Hello Antonio,

Do you care (enough) to share ? :) timer code [even if it's just a recipe] and [minimal] example? Maybe on the wiki ?

-L

> > Michael. >

Reply by email

Antonio Fortuny
to Lukasz Sokol

Le 17/01/2014 16:02, Lukasz Sokol a ?crit :

Hello Antonio, Do you care (enough) to share ? :)

Absolutely not: I'm just thinking that some FPC specialists over there could even enhance it. Just tell me how and where (I already have an access to the wiki pages on update)
You could maybe prepare the page layout and I'll fill in details, code and explanations. I'm not (yet) a specialist on page publications but I guess I'll become one in a short period of time.

timer code [even if it's just a recipe]

Full code, no problem.

and [minimal] example? Maybe on the wiki ?

OK

Antonio.

Show quoted text 10 lines
-L >> Michael. >> -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140117/00779e03/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: agbfhdii.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140117/00779e03/attachment.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: gdigjfga.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140117/00779e03/attachment-0001.jpg>

Reply by email

Lukasz Sokol
to Antonio Fortuny
Antonio Fortuny wrote 12 lines
Le 17/01/2014 16:02, Lukasz Sokol a ?crit : > > Hello Antonio, > > Do you care (enough) to share ? :) Absolutely not: I'm just thinking that some FPC specialists over there could even enhance it. Just tell me how and where (I already have an access to the wiki pages on update) You could maybe prepare the page layout and I'll fill in details, code and explanations. I'm not (yet) a specialist on page publications but I guess I'll become one in a short period of time.

I think you could just copy some other pages' layout / see how other interesting pages are built and create new page similarly, or add this to an existing page about timers if any; That's all I ever did on the Wiki really.

Any way you'll do that, will be an improvement :)

-L.

Show quoted text 11 lines
> timer code [even if it's just a recipe] Full code, no problem. > and [minimal] example? Maybe on the wiki ? OK Antonio. > > -L >>> Michael. >>> >

Reply by email