Thread Crash Protection

Q

quortex

Hi,

I have a server messaging system which marshals (serialises) message
objects to and from a comms system. i..e listens/sends over a udp port.

I have multiple threads that process messages in parallel. Basically
what I would like to achieve is a way of isolating these running
threads from each other so that if a thread crashes the other threads
continue to run.

Ideally I would also like to be able to detect this and restart the
worker thread that crashed so it can start picking up messages again.

Is this possible? Do I need to be looking at application domains to
solve this problem? Obviously web servers do something similar to this,
how hard is it to achieve?

Kind Regards,
Mark
 
J

Jon Skeet [C# MVP]

I have a server messaging system which marshals (serialises) message
objects to and from a comms system. i..e listens/sends over a udp port.

I have multiple threads that process messages in parallel. Basically
what I would like to achieve is a way of isolating these running
threads from each other so that if a thread crashes the other threads
continue to run.

Ideally I would also like to be able to detect this and restart the
worker thread that crashed so it can start picking up messages again.

Is this possible? Do I need to be looking at application domains to
solve this problem? Obviously web servers do something similar to this,
how hard is it to achieve?

What kind of crashes are you expecting? If it's just a case of
exceptions, then you just need normal exception handling to notice that
something has gone wrong in one thread - the other threads don't need
to do anything special.
 
Q

quortex

Hi John,

This is a very good point actually I think I have been overcomplicating
the matter. Probably thinking about it too much.

I guess all I need to do is catch any exceptions that are raised and
detect this in the host process and restart the worker thread.

The only thing I assume this will not cover is fatal errors such as
accessing invalid memory such as multithreaded locking errors etc. It
would be good if I could handle any kind of failure within the thread
and report it rather than bringing the server down.

Catching any unhandled exception though would definitely be the most
simple solution and it most suitable.

Kind Regards,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top