in reply to How to terminate threads that hang or never return?

The problem that we keep encountering is that randomly the threads hang or never return.

For a thread to be joinable, it must "return" from it's code block with a return statement, OR reach the end of the code block.

Since you didn't show how you wrote &somefunction, I can only generalize.

sub somefunction{ # somehow incorporate an alarm or a loop # to run a "return" or "goto END" ....... if ( $shared_flag ==1 ){ return } #or if( $shared_flag == 1 ){ goto END } ...... ...... END: }
or maybe alarm?
sub somefunction{ local $SIG{ALRM} = sub { goto END }; alarm 10; # wait 10 seconds before interrupting while (1){sleep} END: }
You can also try to detach the thread, and have it set a shared variable when it successfully completes. Then loop through the shared flags at the end of your main thread, and kill hanging threads.

I'm not really a human, but I play one on earth. flash japh