[fpc-devel] Threads not working in console application
jura at cp-lab.com
Thu Dec 6 13:58:57 CET 2007
From: "Graeme Geldenhuys" <graemeg.lists at gmail.com>
> I've created a while back a thread based Timer. At the time I
> developed the timer, I tested it in a Lazarus (LCL) GUI application
> and everything worked perfectly. Just tested it now and it still
> Today I tried to use that Timer in a Console application and a fpGUI
> based application and the timer doesn't work for some reason! I'm
> using FPC 2.2.0 under Linux.
> I attached a Console test project and the threadtimer.pas unit. Has
> anybody got any ideas as to why it doesn't work in a console app?
> To get the console app to continue running, I have a loop checking
> a file or sleeps for 500 ms. The timer is enabled before that loop
> starts, so I am supposed to see output to the console. I added some
> debug writeln()'s to know when the time starts or stops and which
> events file (application loop or timer event).
The thread itself works, but not Synchronize() method.
You need to call CheckSynchronize inside main loop.
More information about the fpc-devel