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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: Win32 ActiveState Perl 5.8 - use threads by BrowserUk
in thread Win32 ActiveState Perl 5.8 - use threads by bdimych

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-23 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found