gpt4 book ai didi

delphi - WaitForMultipleObjects 和 64 个线程

转载 作者:行者123 更新时间:2023-12-02 11:17:01 25 4
gpt4 key购买 nike

根据微软的文档MAXIMUM_WAIT_OBJECTS64(要等待的最大句柄数),但有时由于某种原因(因为随机)WaitForMultipleObjects返回 WAIT_FAILED ($FFFFFFFF),GetLastError 返回 ERROR_INVALID_HANDLE (6)。我做错了什么?

procedure TForm1.Button1Click(Sender: TObject);
var ArrayOfHandles:array of THandle;
Threads,x:byte;
ReturnValue:Cardinal;
begin

Threads:=64;
SetLength(ArrayOfHandles,Threads);

for x:=0 to Threads-1 do
begin
WorkerThread:= TWorkerThread.Create(True);
ArrayOfHandles[x]:=WorkerThread.Handle;
WorkerThread.FreeOnTerminate:=true;
WorkerThread.Priority := tpNormal;
WorkerThread.Resume;
end;

ReturnValue:=WaitForMultipleObjects(Threads,@ArrayOfHandles[0],false,INFINITE);
ShowMessage('ReturnValue='+IntToStr(ReturnValue)+#13+'GetLastError='+IntToStr(GetLastError));

end;

procedure TWorkerThread.Execute;
begin

sleep( Random(1000) );

end;

最佳答案

好的。我是个白痴。这一定是假的!

WorkerThread.FreeOnTerminate:=false;

关于delphi - WaitForMultipleObjects 和 64 个线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45651142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com