Hi! I have a similar problem when using threads with synchronize... And I understand that threads in FPC/Lazarus under Linux/BSD works like this:
When you call synchronize from inside of you thread, this sends a message to application thread with the procedure that will be used to synchronize AND WAIT FOR a response from application thread of the execution of sync procedure. BUT when you call Thread.WaitFor in application thread, the application don't process any messages because it is waiting the thread finish, and thread don't finish because it is waiting a response of application thread of the execution of sync procedure... and you have your aplication freeze! My solution in this case is override the WaitFor procedure... procedure TMyThread.WaitFor; begin while not ended do application.processmessages; end; ...and var ended must be set to true in the last line of procedure execute... Fabio Luis Girardi 2008/9/16 Luca Olivetti <[EMAIL PROTECTED]> > En/na Graeme Geldenhuys ha escrit: > > >> procedure TtiLogToCacheAbs.Terminate; >> begin >> writeln('>> TtiLogToCacheAbs.Terminate'); >> FThrdLog.Terminate; >> writeln(' called .Terminate() and now calling .WaitFor()'); >> FThrdLog.WaitFor; >> writeln('<< TtiLogToCacheAbs.Terminate'); >> end; >> >> Any ideas? >> > > Do you call synchronize inside the thread? > Anyway, I don't usually call WaitFor (I've had many problems with it), I > set a flag in the thread and I loop sleeping (or calling checksynchronize if > the thread uses synchronize) until it's true, eg: > > procedure TMyThread.execute; > begin > while not terminated do > begin > .... > end; > finished:=true; > end; > > > > > MyThread.Terminate; > while not MyThread.Finished do sleep(100); > > or > > while not MyThread.Finished do CheckSynchronize(100); > > Bye > -- > Luca > > > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal