views:

72

answers:

3

Hi,

I'm working on a small project involving the creation of a console program intended to be run in background by a larger product.

The program is supposed to talk with the main product (IP21) on one hand and act as a server, handling several clients, on the other.

I've started working on the architecture and came up with something based on a reactor handling events such as connections or events generated by the main product. The client handling part is taken care of in separate threads, one per client.

But I disagree with a colleague of mine on this architecture. He says I should put the reactor and the few other components running in the main thread, in a separate thread. The main thread should be as simple as possible. I'd do that so that the program doesn't crash if this part does. He says it's better to have a completely non-functional program than a violent crash.

I say it's better to fail fast. If this (critical) part of the program crashes there is no reason to try keeping it alive. Moreover I believe it can cause trouble to the user; He will notice something is wrong but if he looks at the task list (our product as some kind of task manager which lists the tasks supposed to be running and allow to easily track a crashed one) he won't notice the program crashed!

I hope you can help us by giving some arguments to one side or the other ;)

edit: thanks for your answers but what we disagree on is about the usefulness of putting the reactor and a few other components in a separate thread in case of serious programming related problem (a segfault/deadlock/<insert critical problem here>). I think it would be both dangerous and pointless to have the program running without this thread.

A: 

Depends on what you need to do and how critical it is. If you can deal with certain steps failing while others work, then fail those steps and keep going. (Think something like sending mail; if one message failed to send, you don't want it to keep the rest from getting through.) Only fail the whole process if the failure of one step makes the rest impossible to do reliably.

cHao
+2  A: 

Use Proactor pattern :)

Fail safe. But it depends on tasks (critical or not) and user' loyalty. Stability. You lost one user or all.

igor
A: 

While editing the question I found this answer on SO which, I think, answers this question too.

f4