waz*_*123 8 delphi multithreading thread-safety
如何创建Thread Safe全局TList?
unit Unit1;
interface
uses
...;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
global_TList: TList; // Not thread safe?
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
// something
end;
end.
Run Code Online (Sandbox Code Playgroud)
我有两个线程,可以写入global_TList,但据我所知,它不是线程安全的.
那么如何让它安全?
Delphi 2010,Indy 10,Win7
dth*_*rpe 19
使用TThreadList.问题解决了.