Recent

Author Topic: A quirk in TTHREAD.Terminate (FPC 3.2.2)  (Read 2203 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 18970
  • Glad to be alive.
Re: A quirk in TTHREAD.Terminate (FPC 3.2.2)
« Reply #15 on: March 02, 2026, 04:31:56 pm »
@LeP
This is not about the language, but about handling proper inter-thread communication and that applies to any language.
That's why we have synchronization primitives like semaphores, events, etc.
If you do not care to use those, you should not bother about using threads either.
It is that simple.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

440bx

  • Hero Member
  • *****
  • Posts: 6364
Re: A quirk in TTHREAD.Terminate (FPC 3.2.2)
« Reply #16 on: March 02, 2026, 07:13:02 pm »
However, If I don't start the thread there is an issue and that is, when calling Terminate, it creates memory leaks detected via HeapTrc.
Since it is your program that starts the thread, your program should know if it has started it or not and behave accordingly.  This fact is very important.

On top of that, I can't seem to devise a way to determine if a thread is actually running before calling Terminate where I can instead just free it.
Even if you could (you can in Windows), as others have already pointed out, there is an inherent race condition between the code that makes the determination and the code that uses the determination's result since there is no guarantee that the state at one point in time is the same at a later point in time.

             
Shouldn't "Terminate" be able to determine if the thread is running and just simply FREE if not?
No.  Your program is responsible for knowing what is has done and not done and take the corresponding actions.

You're expecting terminate to do work that is your program's responsibility to carry out and, in addition to that, it cannot carry out correctly in all cases.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LeP

  • Full Member
  • ***
  • Posts: 241
Re: A quirk in TTHREAD.Terminate (FPC 3.2.2)
« Reply #17 on: March 02, 2026, 07:26:57 pm »
@LeP
This is not about the language, but about handling proper inter-thread communication and that applies to any language.
That's why we have synchronization primitives like semaphores, events, etc.
If you do not care to use those, you should not bother about using threads either.
It is that simple.
I always write that I USE SYNC OBJECTS, so ?
And I use threads (near 30 / 40) in my applications without any issue, since years.
But that doesn't mean that I made right.

You are go around the same question that cannot be resolved until there isn't a standard way to operate.
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

 

TinyPortal © 2005-2018