Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Win32 ActiveState Perl 5.8 - use threads

by BrowserUk (Patriarch)
on Jan 03, 2005 at 12:31 UTC ( #418926=note: print w/replies, xml ) Need Help??

in reply to Win32 ActiveState Perl 5.8 - use threads

Whether it is possible to determine that thread is finished not using additional variables through threads::shared

Yes, with a caveat. You cannot do anything else whilst you wait for it to complete.

use threads; my $thread = async {sleep 10; print "Ok\n"; return 1 }; my $returnValue = $thread->join; print $thread->tid, ' completed and returned: ', $returnValue, "\n";

join will wait for it's referrent thread to terminate. However, once you enter that wait state there is no way to regain control until the thread terminates, which means doing anything else whilst you wait is impossible and if the thread hangs, deadlocks or disappears up it's own bum in an endless loop, you can do nothing about it!

This is one (of several) of the anacronisms of the POSIX pthreads API that Perl's iThreads emulate.

For this reason, I always detach my threads (throwing away any return value and rendering the join API useless) and arrange my own mechanisms for detecting when a thread is finished.

I'd prefer not have to do this "roll-my-own" adminstrative code, but the broken API makes it impossible to do otherwise and retain control

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2023-12-06 20:01 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (31 votes). Check out past polls.