Re: [Lazarus] TFPTimer, Linux

2014-01-20 Thread Lukasz Sokol
On 17/01/14 15:21, Antonio Fortuny wrote:
 
 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.

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




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TFPTimer, Linux

2014-01-17 Thread Antonio Fortuny



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 connected at runtime.
In 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;



Michael.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
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



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TFPTimer, Linux

2014-01-17 Thread Lukasz Sokol
On 17/01/14 14:56, Antonio Fortuny wrote:
 
 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
 connected at runtime. In 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.
 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TFPTimer, Linux

2014-01-17 Thread Antonio Fortuny

  
  

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.

  

-L

  



  
Michael.



  
  

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus



-- 
  

  
  
  
  
 Antonio
Fortuny
  Senior Software engineer
  
  220, avenue de la Libert
  L-4602 Niederkorn
  Tel.: +352 58 00 93 - 93
  www.sitasoftware.lu

  
  
  
  

  





	
		
			

			
		
		
			
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection Antivirus avast! est active.
			
		
	




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] TFPTimer, Linux

2014-01-15 Thread 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



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TFPTimer, Linux

2014-01-15 Thread Michael Van Canneyt



On Wed, 15 Jan 2014, Antonio Fortuny wrote:


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.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus