G
guaiguaizhang
Unregistered / Unconfirmed
GUEST, unregistred user!
我在主线程中开了若干个子线程,程序就运行不正常了,程序如下
主线程
var
thread1 : array of TThread1;
thread_length : integer;
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
thread_length := 5;
setlength(Thread1, thread_length);
for i:=0 to thread_length-1do
thread1 := TThread1.create(false);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
for i:=0 to thread_length-1do
thread1.terminate;
end;
子线程
procedure TThread1.Execute;
begin
repeat
if terminated then
exit;
...
until false;
end;
主线程
var
thread1 : array of TThread1;
thread_length : integer;
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
thread_length := 5;
setlength(Thread1, thread_length);
for i:=0 to thread_length-1do
thread1 := TThread1.create(false);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
for i:=0 to thread_length-1do
thread1.terminate;
end;
子线程
procedure TThread1.Execute;
begin
repeat
if terminated then
exit;
...
until false;
end;