Search code examples
multithreadingdelphiprocessdelphi-7destructor

Does a thread terminate automatically if its main process is forcefully ended?


I need to know, when working with a thread (TThread) in Delphi 7, if I forcefully kill the process, will the thread be terminated or will it keep on going?

My execute procedure looks like this below, which if the thread is terminated, then this will stop. But what if the thread is never officially terminated?

procedure TJDApplicationThread.Execute;
var
  ST: Integer;
begin
  ST:= 5;
  fStop:= False;
  while (not Terminated) and (not fStop) do begin
    //----- BEGIN -----

    Synchronize(DoSync);

    //-----  END  -----
    //Sleep(1000 * ST);
  end;
end;

Solution

  • Because in user mode, threads cannot exist without a process attached to them, the thread will terminate automatically. However, there may be a delay for process to terminate completely if that thread is doing something that cannot be interrupted immediately (e.g. some I/O operations)