Let’s say I have 10 threads running simultaneously. Is there any way of calling some method when a thread finishes? I was thinking of something like:
$thread->onFinish(sub { print "I'm done"; });
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The question you ask in the title and the one you ask in the body are different.
The standard way for a different thread to find out if a thread is still running is to either wait for it or poll it using
is_runningand/oris_joinabledepending on your particular needs.If all you want is for the
i'm doneto be printed, well, make sure that is the last statement executed in the thread body, and it will be printed.