简体   繁体   English

Delphi:如何创建线程安全全局TList?

[英]Delphi: How to create a Thread Safe global TList?

How to create a Thread Safe global TList ? 如何创建线程安全全局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.

I have two threads, which can write to global_TList , but as I know, it's not thread safe. 我有两个线程,它们可以写入global_TList,但是据我所知,它不是线程安全的。

So how to make it safe? 那么如何使其安全呢?

Delphi 2010, Indy 10, Win7 Delphi 2010,Indy 10,Win7

Use TThreadList. 使用TThreadList。 Problem solved. 问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM