[Lazarus] TThread.WaitFor blocks the main event loop under Linux

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Oct 12 10:57:28 CEST 2010


On 12 October 2010 10:51, Michael Schnell <mschnell at lumino.de> wrote:
>
> So -> OP:
> does it work decently in Linux ?

No!  No matter where I call MyThread.WaitFor() I get a instand
deadlock under Linux. I had to reintroduce a FPC only WaitFor method
in a TTHread descendant, that instead uses the Finised boolean
variable. A virtual Execute() method is also implemented that uses a
interface object to initially set Finised to False, and then when that
interface goes out of scope (when Execute is completed), it
automatically sets Finished to True.  So my reintroduced WaitFor is
implemented as follows:

procedure  TMyBaseThread.WaitFor;
begin
  while not FFinished do CheckSynchronize(100);
end;

Unfortunately WaitFor is not virtual, so I had to use reintroduce, and
wrapped in in IFDEF FPC because Delphi doesn't require this.

I actually think my solution should be the default implementation for
TThread.WaitFor() in FPC - this will prevent deadlocks under platforms
other than Windows.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net:8080/fpgui/




More information about the Lazarus mailing list