[fpc-devel] Threads not working in console application

Yury Sidorov jura at cp-lab.com
Thu Dec 6 15:21:36 CET 2007


From: "Graeme Geldenhuys" <graemeg.lists at gmail.com>
> On 06/12/2007, Yury Sidorov <jura at cp-lab.com> wrote:
>>
>> The thread itself works, but not Synchronize() method.
>> You need to call CheckSynchronize inside main loop.
>>
>
> Ah, thanks Yury!  That also means that having the main loop fire 
> every
> 500ms (it was just a test for the console app), my timer cannot fire
> it's events in less than 500ms (eg: timer.Interval := 200).
>
>  while True do
>  begin
>    if FileExists('killme') then
>      break;
>    Sleep(500);
>    CheckSynchronize;
>    writeln('event loop');
>  end;
>
>
> As a test, I set the main loop's Sleep() to 10ms and the app didn't
> even register in 'top' for CPU usage, so I guess it's ok to set
> sleep() with such a small time?
> Not that I intend to use the Timer interval for <500ms though.

AFAIK you can remove Sleep(500); and replace it by 
CheckSynchronize(500);

Yury. 



More information about the fpc-devel mailing list