Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to terminate threads that hang or never return?

by zentara (Archbishop)
on Jun 02, 2006 at 16:21 UTC ( [id://553330]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-23 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found