Eric Rybski wrote:
> I was parsing through some documentation from the old
> Thread.pm (Perl 5.6), and noticed the following:
>
> join
> join waits for a thread to end and returns any values
> the thread exited with. join will block until the
> thread has ended, though it won't block if the thread
> has already terminated.
>
> If the thread being joined died, the error it died
> with will be returned at this time. If you don't want
> the thread performing the join to die as well, you
> should either wrap the join in an eval or use the eval
> thread method instead of join.
>
> eval
> The eval method wraps an eval around a join, and so
> waits for a thread to exit, passing along any values
> the thread might have returned. Errors, of course, get
> placed into [EMAIL PROTECTED]
>
> Is there any reason this does not exist in modern
> ithreads? Being able to detect the reason why a thread
> existed during join could be extremely useful. As it is,
> I currently use a kludgy method (by trapping die and
> making it available via a shared datastructure) in some
> application to make a best guess as to the reason behind
> terminated threads.
>
> Would there be interest in re-adding it? Perhaps, to keep
> consistent behavior, $thr->join() could act like the old
> Thread.pm $thr->eval(), and a new method,
> $thr->join_noeval() could be added?
>
> Or, perhaps to be _really_ consistent with current ithread
> behavior (join has no affect on the value of $@), but add
> two new methods:
> $thr->join_eval() # join and propegate $@ from
> # thread, if defined
> $thr->join_noeval() # join and die with value of $@
> # from thread, if defined
I don't think that messing with $@ would be a good idea as
there might be difficult to untangle interactions with
joining a thread inside an eval:
eval {
....
$thr->join_eval();
...
};
I think it would be simpler just to have an ->err() method
that could be called after (or even before) a thread is
joined:
my $result = $thr->join();
if ($thr->err()) {
die('Thread error: ' . $thr->err());
}
I implemented this in the 'threads' module code, and if
there is a concensus on the syntax, I'll submit a patch to
blead and release a new version of 'threads' to CPAN.
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com