Recent

Author Topic: application->terminate makes application unresponsive  (Read 771 times)

aducom

  • Full Member
  • ***
  • Posts: 162
    • http://www.aducom.com
application->terminate makes application unresponsive
« on: January 24, 2025, 11:49:17 am »
I have migrated to version 3.4, and am testing my current applications. There is one issue I cannot figure out. I use application->terminate, but instead of terminating the application, it simply makes the application unresponsive. I paused the application to see what was going on, and it stopped at a line on the procedure ntdll.RtlUserThreadStart
and a lot of assembler.
I found some similar old posts, but I got not much info from these. Is there a way to find out why this is happening? The old application works as expected.


aducom

  • Full Member
  • ***
  • Posts: 162
    • http://www.aducom.com
Re: application->terminate makes application unresponsive
« Reply #1 on: January 24, 2025, 12:03:59 pm »
I managed to fix the issue by replacing application->terminate by a simple close. Should have done that in the first place, it's an old application. But the question remains as the behaviour of application->terminates seems to be different.

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: application->terminate makes application unresponsive
« Reply #2 on: January 24, 2025, 12:55:46 pm »
The rtl call seems to indicate a mutithreaded application.
When you then call application.terminate without a thread.waitfor you run the risk of a hang.
The waitfor is needed for all threads. Strange that a simple close works.
« Last Edit: January 24, 2025, 12:57:46 pm by Thaddy »
But I am sure they don't want the Trumps back...

aducom

  • Full Member
  • ***
  • Posts: 162
    • http://www.aducom.com
Re: application->terminate makes application unresponsive
« Reply #3 on: January 24, 2025, 01:21:57 pm »
The application does use threads, but only to perform tasks per user request. The thread is started and until it is done, the user cannot close the program.  The odd thing that it worked perfectly before. But I agree, it is odd, and the routine implies something with threads. Will try to look into it deeper, as it has to come from somewhere ;-) Thnx for answering

cdbc

  • Hero Member
  • *****
  • Posts: 1847
    • http://www.cdbc.dk
Re: application->terminate makes application unresponsive
« Reply #4 on: January 24, 2025, 02:05:06 pm »
Hi
I've sometimes got bitten by 'EndThread'!!!
It's to be used in the 'threadfunc' when you're NOT joining the thread, i.e.: Waitfor joins the thread.
What I've experienced is this, if the thread is waitfor'ed / joined and has a 'EndThread' call in the threadfunc, it hangs!
Otoh, if you don't use 'EndThread' and you're NOT joining, you'll leak system resources...
Just my 2 cent's worth
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

robert rozee

  • Full Member
  • ***
  • Posts: 216
Re: application->terminate makes application unresponsive
« Reply #5 on: January 24, 2025, 05:44:07 pm »
i have a program that has a couple of threads running, these are started with:

Code: Pascal  [Select][+][-]
  1.   TSerialThread.Create(false);                                         // start serial I/O thread
  2.   TCheckThread.Create(false)                                           // start bell thread

upon exiting the program i do nothing special to shut down the threads, beyond setting a couple of flags that ensure they are just spinning doing nothing important.

should i be terminating the threads before exiting? i've never seen anything bad happen by just letting them die when the program ends. the program has both Linux and win32 versions.


cheers,
rob   :-)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1468
    • Lebeau Software
Re: application->terminate makes application unresponsive
« Reply #6 on: January 24, 2025, 08:58:28 pm »
upon exiting the program i do nothing special to shut down the threads, beyond setting a couple of flags that ensure they are just spinning doing nothing important.

should i be terminating the threads before exiting?

Yes. You should always terminate your threads cleanly and wait for them to fully terminate.

i've never seen anything bad happen by just letting them die when the program ends. the program has both Linux and win32 versions.

That depends on what the threads actually do.

For example, on Windows, if a thread owns the lock on a mutex, and then the thread ends abruptly (including process termination), the lock is released implicitly by the OS.  The next thread to lock that same mutex will get ownership (and be told of the abandonment), but the state of the data that the mutex was protecting will be unknown and the data should not be relied on.  But many apps don't handle mutex abandonment properly.
« Last Edit: January 24, 2025, 09:01:25 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8221
Re: application->terminate makes application unresponsive
« Reply #7 on: January 24, 2025, 09:42:14 pm »
Yes. You should always terminate your threads cleanly and wait for them to fully terminate.

I take very little pleasure in raising my head above the parapet here, but I believe I've seen situations where e.g. a direct call to the Linux (Berkeley sockets) API without a timeout has kept a thread in a state where it didn't terminate.

I've also explored sending SIGHUP to a thread and found it problematic... I'd have to check my notes but I think that it dissipated to the overall process with fatal results.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018