You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I run into a situation with Delphi XE 10.2.1 where the code below (VirtualTrees.pas) leaves my application in a deadlock when the application closes:
if WorkerThread.FRefCount = 0 then
begin
with WorkerThread do
begin
Terminate;
SetEvent(WorkEvent);
end;
FreeAndNil(WorkerThread);
CloseHandle(WorkEvent);
end;
The destructor of WorkerThread (called with FreeAndNil) will not finish and will hang on de Win32 API call EndThread. I'm assuming that this has to do with the WorkEvent that is not properly handled while being destroyed at the same time.
By not calling FreeAndNil(WorkerThread), but instead using FreeOnTerminate, see the code below, fixes this issue for me.
// Create worker thread, initialize it and send it to its wait loop.
WorkerThread := TWorkerThread.Create(False);
WorkerThread.FreeOnTerminate := True;
Cheers,
J.
The text was updated successfully, but these errors were encountered:
I run into a situation with Delphi XE 10.2.1 where the code below (VirtualTrees.pas) leaves my application in a deadlock when the application closes:
The destructor of WorkerThread (called with FreeAndNil) will not finish and will hang on de Win32 API call EndThread. I'm assuming that this has to do with the WorkEvent that is not properly handled while being destroyed at the same time.
By not calling FreeAndNil(WorkerThread), but instead using FreeOnTerminate, see the code below, fixes this issue for me.
Cheers,
J.
The text was updated successfully, but these errors were encountered: