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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.