Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should you code in case the threads die or freeze?

Tags:

c#

I have an app that starts 10 threads. Each thread does it's work and waits (using the producer consumer model). So when more work comes along, one of the threads is unblocked and it does the work.

A colleague at work insists I should write some code that monitors the threads "just in case" they freeze/do not respond or die.

So far in my testing, they work fine and close down correctly.

My question is "should I put code in to do this"? If so, "how do I monitor a thread and check it's status"?

Thanks. JD

like image 944
JD. Avatar asked Dec 13 '22 03:12

JD.


2 Answers

It really depends on the situation. First of all, you should focus on correctness so that it doesn't freeze or die but if you need more reliability, you should first think about how you can gracefully recover from such a situation. You should think about why it might freeze or die and if it did, now what you can do. If you can't do anything good that reliably recovers from such a situation, you shouldn't even try. If can do it without making the situation worse, then you can go and try doing so.

Obviously, if you made such a choice, you have to be careful not to mess things up and introduce some bugs that actually make the bad stuff happen yourself.

like image 121
mmx Avatar answered Jan 03 '23 01:01

mmx


Ideally no, your threads should be able to finish properly. Monitoring them is not worth the complexity and processing time. If you do it correctly you won't need monitoring.

like image 45
Otávio Décio Avatar answered Jan 03 '23 01:01

Otávio Décio