Al Boldi wrote: > Micha Nelissen wrote: > > Al Boldi wrote: > > > I think the race comes in when you have two competing threads wanting > > > to synchronize the the main thread. It just hangs. > > > > Are you sure? This should work properly. Can you provide example (in a > > bugreport)? > > Well, it's not easily repeatable, and seems to be very OS dependent. On > linux, I work around this problem by inserting a sleep(0) just before the > synchronize. > > But there is another problem, it seems FreeOnTerminate doesn't actually > free the memory on exit, unless the main thread actually waits for it to > terminate, and this is on linux again. Can you confirm this?
I played with this some more, and it turns out that not only is FreeOnTerminate completely broken but Free only frees the OS-thread memory if the thread is still running or is preceded by a WaitFor. This is on fpc2.0.2/linux. Maybe this has been fixed in 2.2.0? Below is the test-code. Can somebody confirm this on other platforms/fpcVersions. Thanks! -- Al --- type { TThreadBug } TThreadBug = class(TThread) public procedure Execute; override; end; { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { private declarations } public { public declarations } t1:TThreadBug; end; var Form1: TForm1; implementation { TThreadBug } procedure TThreadBug.Execute; begin writeln('just ran a thread... done!'); end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin t1:=TThreadBug.Create(false); end; procedure TForm1.Button2Click(Sender: TObject); begin t1.Free; // Only frees RTL object memory // OS-thread memory left dangling end; procedure TForm1.Button3Click(Sender: TObject); begin t1.WaitFor; // Correctly frees OS-thread memory t1.Free; // Frees RTL object memory end; _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives