|There's more than one way to do things|
[Thread::Queue] How to handle unexpected termination and time out in threadsby oobobe (Novice)
|on Apr 09, 2014 at 08:36 UTC||Need Help??|
oobobe has asked for the
wisdom of the Perl Monks concerning the following question:
I'm really struggling on how to get threads to work properly in my code. I've searched the web for days, but I still can't figure out a way to handle what I want. Maybe I'm just stupid. But, if anyone here can give me an idea no how to do this, I truly appreciate it.
I need to run threads to compare 2 versions of texts (thousands of them.) I also need to set a thread limit so that those thousands of threads won't eat away my CPU and memory.
However, there are a couple of things that can happens in the threads, but currently my code can't handle them.
1. Some threads may be terminated unexpectedly. How can I catch those threads to re-run them or handle them gracefully?
2. When some threads hang, how can I time out those threads?The Thread::Queue code I have below is something I saw somewhere in the web:
So, when a worker thread die unexpectedly, where can I insert code to handle it?
And, when a worker thread hangs for too long, where in the code can I time it out?
Another somewhat related question, it seems that String::Diff (Text::Diff::FormattedHTML too) doesn't work well in threads. The program will die with "Bus Error: 10" when running String::Diff in threads (usually happens after hundreds of threads are executed.) If I use Text::Diff instead, I don't see "Bus Error: 10". But Text:Diff is too obscure for my targeted users, is there a way to run String::Diff safely in threads?
Thank you very much