En/na Luca Olivetti ha escrit:
Yes, it's necessary because the LCL is not multi-thread safe.
Ok, I thought it was.
The chances of two threads changing the same variable in the same
object is very low so you probably won't notice, but that doesn't mean
there is no bug.
Yes, I know the issues. Now I wonder how well is USE_SYNCHRONIZE tested
since it's not the default option.
I just made a quick test with an old copy of lazarus (0.9.6) I had
installed in windows (where USE_SYNCHRONIZE is enabled by default): if I
use synchronize I get a lot of 'thread' lines in memo1 insted of one per
call.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
Buttons,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Form1Show(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
TMyThread = class(TThread)
procedure Execute;override;
procedure Ref;
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TMyThread.Execute;
var i:integer;
begin
for i:=1 to 10 do
begin
synchronize(@ref);
//ref;
sleep(5000);
end;
end;
procedure TMyThread.Ref;
begin
Form1.Memo1.Lines.Add('thread');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add('main');
end;
procedure TForm1.Form1Show(Sender: TObject);
begin
TMyThread.Create(false);
end;
initialization
{$I unit1.lrs}
end.
Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004 Fax +34 93 5883007
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives