Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/Thread support    [ Add a report in this area ]  
Report #:  97180   Status: Open
TThread.Terminate should be marked as virtual
Project:  Delphi Build #:  3953
Version:    15.1 Submitted By:   Mason Wheeler
Report Type:  Suggestion / Enhancement Request Date Reported:  8/4/2011 6:49:30 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   286052
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: 14
One of the frustrating issues that I run into over and over again in server development is the inability to do anything else when you call .Terminate on a thread. There's a TThread.OnTerminate event handler, but the name is very deceptive. It doesn't run when you call Terminate; it only runs after Execute has returned. And Terminate is not virtual, so you can't override it. This makes simple work-processing threads much more complex than they need to be.

Ideally, I could write a thread like this, where FSignal is a SyncObjs.TSimpleEvent:

procedure TWorkProcessor.Execute;
  while not self.Terminated do
    while ProcessNewTasks() = true do ;
    if not Self.Terminated then

procedure TWorkProcessor.Terminate;
  inherited Terminate;

But since I have no way to execute arbitrary code when the thread is signaled for termination, I instead have to add a bunch of extra complexity to the Execute method. I think marking TThread.Terminate as virtual would be a very simple way to add a lot of useful possibilities to the class.
Steps to Reproduce:


Server Response from: ETNACODE01