Recent

Author Topic: Feature Requst: TThread.TerminatedSet  (Read 2637 times)

Zaher

  • Hero Member
  • *****
  • Posts: 680
    • parmaja.org
Feature Requst: TThread.TerminatedSet
« on: July 18, 2020, 06:19:36 pm »
Not just for compatible with Delphi, I need a method to override it, when someone/code called thread.Terminate
In Delphi it is TerminatedSet

I will report it in the bug tracker. if it acceptable.

EDIT
Fixed to TerminatedSet
« Last Edit: July 18, 2020, 11:57:22 pm by Zaher »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Feature Requst: TThread.TerminateSet
« Reply #1 on: July 18, 2020, 06:29:05 pm »
What's the problem ? I don't fully understand here.

Using the Terminate method it sets the Terminated property to true but that's it. From there your code in the thread should be monitoring that property at all times during its loop and if is set then it just exits.

 I don't see a difference ?

EDIT:

  Maybe you are looking for an early warning so that other threads can test if the Terminate has been called but not yet satisfied ? Is that it ?


« Last Edit: July 18, 2020, 06:31:13 pm by jamie »
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Feature Requst: TThread.TerminateSet
« Reply #2 on: July 18, 2020, 06:48:51 pm »
Currently you need to build your thread based from a TThread class now so that means you can have in class a field that is set via the Terminate call to reflect this..

I suppose it would be a good idea to report this as a wish  :)
The only true wisdom is knowing you know nothing

Zaher

  • Hero Member
  • *****
  • Posts: 680
    • parmaja.org
Re: Feature Requst: TThread.TerminateSet
« Reply #3 on: July 18, 2020, 07:10:15 pm »
Ah ok, I always need Terminate as virtual method to override it when called I stop actions,
Like: Socket reading and waiting, when I want to stop reading, I close the handle of socket, that stop reading then exit from read.
Also if I am in waiting event etc etc, I setEvent to exit from waiting, when trigger terminate, I need to call my own method Stop after or before it to make this action, I need it offical, if I call Terminate, i want to do that things.

that one of my real project needs it

https://github.com/parmaja/minilib/blob/master/socket/source/mnIRCClients.pas#L1935
https://github.com/parmaja/minilib/blob/master/socket/source/mnIRCClients.pas#L1849
https://github.com/parmaja/minilib/blob/master/socket/source/mnIRCClients.pas#L1599

make Terminate as virtual is good for me, or add TerminateSet as in Delphi that better just to make my code compiled in both FPC and Delphi


rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Feature Requst: TThread.TerminateSet
« Reply #5 on: July 18, 2020, 07:29:09 pm »
make Terminate as virtual is good for me, or add TerminateSet as in Delphi that better just to make my code compiled in both FPC and Delphi
TerminateSet??? Do you mean TThread.TerminatedSet?
http://docwiki.embarcadero.com/Libraries/Rio/en/System.Classes.TThread.TerminatedSet

Does Embarcadero have any documentation (other than that empty page)?

https://stackoverflow.com/questions/33962710/implement-override-for-thread-terminate-method

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Feature Requst: TThread.TerminateSet
« Reply #6 on: July 18, 2020, 09:26:36 pm »
Terminate(XXX) without waitfor is useless.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.


jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Feature Requst: TThread.TerminatedSet
« Reply #8 on: July 19, 2020, 04:02:34 am »
Yes, I hope they put that feature in. That way other threads can check to see if it was set for a terminate state but not depend on it just because it is still running..



 if Mythread.TerminatedSet then Don't_Bother_To_dependOnThread_Being_valid;

What they should have done instead of using "CheckTerminated" would be to CheckRunningState:Integer;
 
   0  := Dead;
   1  := Running;
   -1 :=Shutting down;

 or use a Set type

 TThreadRuningState = (tsStopped, TsRunning, tsShuttingDown);

etc

have fun..





The only true wisdom is knowing you know nothing

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Feature Requst: TThread.TerminatedSet
« Reply #9 on: July 19, 2020, 05:41:35 am »
Yes, I hope they put that feature in. That way other threads can check to see if it was set for a terminate state but not depend on it just because it is still running..

if Mythread.TerminatedSet then Don't_Bother_To_dependOnThread_Being_valid;
TThread.TerminatedSet is not a function in Delphi.
Look at http://docwiki.embarcadero.com/Libraries/Rio/en/System.Classes.TThread.TerminatedSet

So you can't use it like you showed/wanted.
For that you have TThread.Terminated and TThread.Finished.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Feature Requst: TThread.TerminatedSet
« Reply #10 on: July 19, 2020, 10:07:31 am »
For that you have TThread.Terminated and TThread.Finished.
And Waitfor

Anyway looks like it is fixed. https://bugs.freepascal.org/view.php?id=37388
« Last Edit: July 19, 2020, 10:09:23 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

coliv_aja

  • New Member
  • *
  • Posts: 38
Re: Feature Requst: TThread.TerminatedSet
« Reply #11 on: September 15, 2020, 03:48:14 am »
I had been masking TThread.Terminate this whole time. because it's not s virtual. And FTerminated is a private var.
Code: Pascal  [Select][+][-]
  1. procedure TMyThread.Terminate;
  2. begin
  3.    inherited Terminate; // to set FTerminated
  4.    socket.abort;
  5. end;
  6.  

But I'm glad there's a virtual method TThread.TerminatedSet to override.

 

TinyPortal © 2005-2018