Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock on application close in ReleaseThreadReference #738

Closed
jpdk opened this issue Nov 13, 2017 · 1 comment
Closed

Deadlock on application close in ReleaseThreadReference #738

jpdk opened this issue Nov 13, 2017 · 1 comment
Assignees
Labels
Milestone

Comments

@jpdk
Copy link

jpdk commented Nov 13, 2017

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.

@joachimmarder joachimmarder self-assigned this Nov 13, 2017
@joachimmarder joachimmarder added this to the V7.0 milestone Nov 13, 2017
joachimmarder pushed a commit that referenced this issue Nov 13, 2017
@joachimmarder
Copy link
Contributor

The suggested change makes sense. Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants