Solved

crashed threads

Posted on 1998-11-09
5
159 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now