beable has asked for the wisdom of the Perl Monks concerning the following question:
Is returning a list broken when using threads? I find the difference in behaviour between calling a subroutine which returns a list in a thread and calling the subroutine directly hard to understand. When calling the subroutine with a thread, I'm only getting the last element of the list back. When I call the subroutine without a thread, I get the whole list. What's going on? The code below is mostly from perlthrtut.
#!/usr/bin/perl use threads; $thr = threads->new(\&sub1); @ReturnData = $thr->join; print "Thread returned @ReturnData\n"; print "array size is: ", scalar(@ReturnData), "\n"; @ReturnData = sub1(); print "Subroutine returned @ReturnData\n"; print "array size is: ", scalar(@ReturnData), "\n"; sub sub1 { return ("Fifty-six", "foo", 23); } __END__ Output: Thread returned 23 array size is: 1 Subroutine returned Fifty-six foo 23 array size is: 3
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is returning a list broken when using threads?
by Errto (Vicar) on Jul 25, 2004 at 02:36 UTC | |
by beable (Friar) on Jul 25, 2004 at 02:55 UTC | |
by BrowserUk (Patriarch) on Jul 25, 2004 at 03:43 UTC | |
by tilly (Archbishop) on Jul 25, 2004 at 04:59 UTC | |
by CountZero (Bishop) on Jul 25, 2004 at 16:24 UTC | |
by chromatic (Archbishop) on Jul 25, 2004 at 20:23 UTC | |
by Errto (Vicar) on Jul 25, 2004 at 20:18 UTC | |
Re: Is returning a list broken when using threads?
by pg (Canon) on Jul 25, 2004 at 16:30 UTC | |
Re: Is returning a list broken when using threads?
by pg (Canon) on Jul 25, 2004 at 20:53 UTC |
Back to
Seekers of Perl Wisdom