非
非走不可
Unregistered / Unconfirmed
GUEST, unregistred user!
本人预利用VCL库中的TThread对象来演示线程。
创建主程序的代码:
procedure mythreadfunc;
//不断累加的计数器
var
i:integer;
dc:hdc;
s:string;
begin
for i:=0 to 100000do
begin
s:=inttostr(i);
dc:=getdc(form1.edit1.handle);
textout(dc,0,0,pchar(s),length(s));
releasedc(form1.edit1.handle,dc);
end;
end;
然后创建Tthread1和Tthread2来观察线程调用:
procedure thread1.show;
begin
myedit.Text:=inttostr(count);
end;
procedure thread1.execute;
var
i:integer;
begin
for i:=0 to 100do
begin
count:=i;
synchronize(show);
end;
end;
procedure thread2.show;
begin
mythreadfunc;
end;
procedure thread2.execute;
begin
synchronize(show);
end;
请问:Tthread1调用是显示是从0到100(这个知道偶Why),但是为什么Tthread2调用的时候显示却是从1000到100000而不是从0到100000?
创建主程序的代码:
procedure mythreadfunc;
//不断累加的计数器
var
i:integer;
dc:hdc;
s:string;
begin
for i:=0 to 100000do
begin
s:=inttostr(i);
dc:=getdc(form1.edit1.handle);
textout(dc,0,0,pchar(s),length(s));
releasedc(form1.edit1.handle,dc);
end;
end;
然后创建Tthread1和Tthread2来观察线程调用:
procedure thread1.show;
begin
myedit.Text:=inttostr(count);
end;
procedure thread1.execute;
var
i:integer;
begin
for i:=0 to 100do
begin
count:=i;
synchronize(show);
end;
end;
procedure thread2.show;
begin
mythreadfunc;
end;
procedure thread2.execute;
begin
synchronize(show);
end;
请问:Tthread1调用是显示是从0到100(这个知道偶Why),但是为什么Tthread2调用的时候显示却是从1000到100000而不是从0到100000?