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

Re: $threads->join() only returns one argument??? BUG?

by Chmrr (Vicar)
on Jun 12, 2003 at 03:39 UTC ( [id://265269]=note: print w/replies, xml ) Need Help??


in reply to $threads->join() only returns one argument??? BUG?

This is pretty obviously a bug. The context that is applied to the $thr->join call is the context that the threads->new call was in. That is:

my $thr = threads->new( sub { return (1,2,3) }); my @a = $thr->join(); print "return is @a\n";

..fails, while..

my ($thr) = threads->new( sub { return (1,2,3) }); my @a = $thr->join(); print "return is @a\n";

..works fine. Note the difference in parens on the my $thr line. I'm going to poke at the threads code on this one.

Update: Upon reflection and looking at the code, it makes sense in a perverse way. Because the subroutine/thread starts execution upon creation, someone could call wantarray from it off the top. If the context was determined at join time, there would be no way to determine the proper wantarray value. In fact, this behavior is documented in bleedperl's threads.pm (search for "context").

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re^2: $threads->join() only returns one argument??? BUG?
by Anonymous Monk on Feb 25, 2010 at 19:29 UTC
    Thanks, I was just running into this issue myself. Even several of the code snippets out there for threads do not take this into account. This one is used in several places
    use Thread; $thr = new Thread \&sub1; @ReturnData = $thr->join; print "Thread returned @ReturnData"; sub sub1 { return "Fifty-six", "foo", 2; }
    It returns two. Some keywords: perl thread return values join multiple last array

    20100226 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

      Just what I needed. Thanks!
Re^2: $threads->join() only returns one argument??? BUG?
by Anonymous Monk on Feb 12, 2015 at 20:35 UTC
    Thanks for info brain was blasted lol

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-29 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found