Linux: TThread, synchronize lazarus / 8-Other ---------------------------------------------------------------------- guest · 2005-11-03 13:50 Linux only: When I use synchronize() method in thread (class TThread), thread hangs there. How can I solve it? Should I use CriticalSections (in Linux) instead? Or leave synchronize? lazarus version:0.9.8 thx for replies ---------------------------------------------------------------------- Vincent Snijders · 2005-11-04 07:38 Can you post some complete (but small) sample code? ---------------------------------------------------------------------- Anonymous · 2005-11-04 09:58 Here is some sapmle code (but synchronize does not work generally for any code) Code: [Select] program project1; {$mode objfpc}{$H+} uses {$ifdef UNIX}   cthreads, {$endif}   Interfaces, // this includes the LCL widgetset   Forms   { add your units here }, Unit1; begin   Application.Initialize;   Application.CreateForm(TForm1, Form1);   Application.Run; end. Code: [Select] unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     procedure Form1Create(Sender: TObject);     procedure Form1Destroy(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; type TH=class(TThread)          M:TMemo;        public          constructor Create(MMM:TMemo);          procedure Execute;override;          procedure Syc;      end; var   Form1: TForm1;   Memo:TMemo;   Thread:TH; implementation { TForm1 } constructor TH.Create(MMM:TMemo); begin    inherited create(false);    M:=MMM;    freeonterminate:=true; end; procedure TH.Execute; begin    repeat      sleep(100);      synchronize(@Syc);      //Syc;    until terminated; end; procedure TH.Syc; begin    if assigned(M) then M.Lines.Add('LLL'); end; procedure TForm1.Form1Create(Sender: TObject); begin    Memo:=TMemo.Create(Self);    Memo.Parent:=self;    Memo.Align:=alclient;    Memo.Lines.Clear;    Thread:=TH.Create(Memo); end; procedure TForm1.Form1Destroy(Sender: TObject); begin    Thread.Terminate;    Memo.Free; end; initialization   {$I unit1.lrs} end. ---------------------------------------------------------------------- Vincent Snijders · 2005-11-04 14:17 You need to recompile the LCL with the -dUSE_SYNCHRONIZE option. Current SVN version, doesn't need that anymore. ---------------------------------------------------------------------- Anonymous · 2005-11-07 13:17 thanks