Solved

crashed threads

Posted on 1998-11-09
5
161 Views
Last Modified: 2010-04-04
how can I tell if a thread has crashed?

if Im running an additional thread, is there an easy way to tell if the thread has crashed?

for that matter, what actually happens when a thread crashes?  in my App, the other threads seem to carry on and not notice that the thread is dead, except when some task that the thread was supposed to perform doesnt happen.
if this thread crashes, somehow the other threads need to know, and shut themselves down gracefully.

thanks

Ben

0
Comment
Question by:1750
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 1346351
Bascially there isn't at least in a passive way. It is equivalent to telling if your application has crashed.

One approach that you can use is to require all threads to periodically update status information in some central location. Failure to do so within a certain length of time implies that the thread may have crashed.

There is no real fool-proof way other than to be very careful how you write the code and use exception handling to catch problems and exit or otherwise deal with them gracefully.

Cheers,

Raymond.

0
 

Author Comment

by:1750
ID: 1346352
would putting a try..finally inside the execute method work?  ie:

procedure TMyThread.Execute;
begin
  try
    .
    .
  finally
    if not terminated then IveCrashed:=True;
  end;
end;

or would I need to use try..except?  Ive never quite understood the difference between the two.  




0
 

Author Comment

by:1750
ID: 1346353
oops!  if forgot to include:

Brain.Engage;

I do know the difference between try..finally and try..except!

ive tried the try..finally scenario, and it doesnt seem to work.

any ideas?


0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1346354
The try except scenario should work if the crash is hapenning due to an exception. However, it may just be getting into an inifinite loop, or is blocked waiting access to a semaphore or mutex which it is never granted etc..

The actual crash might be happening the the synchronise method in which case it is occurring in the main VCL thread (which might explain whay a try..finally doesn't seem to work...). Though I would have thought this would still generate an exception (which it might but is being caught and ignored...)

Raymond.

0
 

Author Comment

by:1750
ID: 1346355
thanks
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question