[Lazarus] timer in a console application
Sven Barth
pascaldragon at googlemail.com
Fri Aug 10 14:59:01 CEST 2012
Am 10.08.2012 14:43, schrieb Michael Schnell:
> On 08/10/2012 02:38 PM, michael.vancanneyt at wisa.be wrote:
>> while not fStopExecution do
>> begin
>> CheckSynchronize;
>> inc(i);
>> end;
> This results in 100 % CPU (in a single CPU system) so not a very good
> idea IMHO. (Even the timer thread is crippled by the main thread.)
>
> If you can live with some latency I would do something like:
>
> while not fStopExecution do
> begin
> CheckSynchronize;
> sleep(Max_Latancy);
> end;
You know that the "inc(i)" in the above code is where the author's
calculation takes place? So the "CheckSynchronize" call would just be
between different calculation steps where it's safe to have the
execution stopped (though it might be better to put the
"CheckSynchronize" to the end of the loop).
Regards,
Sven
More information about the Lazarus
mailing list