xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
I found that output is different with the running times. According to warnings, it seems some threads already quit when another thread running. All threads must quit all together? That's odd! Then I add 'sleep' in the sub route to try to delay thread quit like below.use threads; $Param3 = "foo"; $thr = threads->new(\&sub1, "Param 1", "Param 2", $Param3); $thr = threads->new(\&sub1, @ParamList); $thr = threads->new(\&sub1, qw(Param1 Param2 Param3)); sub sub1 { my @InboundParameters = @_; print "In the thread\n"; print "got parameters >", join("<>", @InboundParameters), "<\n" +; } __OUTPUT__ D:\>perl thr_test.pl In the thread got parameters >Param 1<>Param 2<>foo< In the thread got parameters >< A thread exited while 2 threads were running. D:\>perl thr_test.pl In the thread got parameters >Param 1<>Param 2<>foo< A thread exited while 3 threads were running. D:\>perl thr_test.pl In the thread got parameters >Param 1<>Param 2<>foo< A thread exited while 3 threads were running.
Warnings is still tossed although the status seems better than before.use strict; use warnings; use threads; no warnings 'threads'; my @ParamList = qw (1 2 3); my $Param3 = "foo"; my $thr = threads->new(\&sub1, "Param 1", "Param 2", $Param3); $thr = threads->new(\&sub1, @ParamList); $thr = threads->new(\&sub1, qw(Param1 Param2 Param3)); sub sub1 { my @InboundParameters = @_; sleep 10; print "In the thread\n"; print "got parameters >", join("<>", @InboundParameters), "<\n" +; } __OUTPUT__ D:\>perl thr_test.pl A thread exited while 4 threads were running. D:\>perl thr_test.pl A thread exited while 4 threads were running. D:\>perl thr_test.pl A thread exited while 4 threads were running. D:\>perl thr_test.pl A thread exited while 4 threads were running.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threads question
by BrowserUk (Patriarch) on Jun 29, 2007 at 04:55 UTC | |
by ikegami (Patriarch) on Jun 29, 2007 at 14:53 UTC | |
by BrowserUk (Patriarch) on Jun 29, 2007 at 15:10 UTC | |
|
Re: Threads question
by TOD (Friar) on Jun 29, 2007 at 02:31 UTC | |
by xiaoyafeng (Deacon) on Jun 29, 2007 at 03:04 UTC | |
by ikegami (Patriarch) on Jun 29, 2007 at 15:18 UTC | |
|
Re: Threads question
by jdrago_999 (Hermit) on Jun 29, 2007 at 04:01 UTC | |
|
Re: Threads question
by zentara (Cardinal) on Jun 29, 2007 at 11:47 UTC | |
by BrowserUk (Patriarch) on Jun 29, 2007 at 14:19 UTC | |
by zentara (Cardinal) on Jun 29, 2007 at 16:28 UTC | |
by BrowserUk (Patriarch) on Jun 29, 2007 at 17:40 UTC | |
by zentara (Cardinal) on Jun 30, 2007 at 12:39 UTC | |
| |
|
Re: Threads question
by shmem (Chancellor) on Jul 01, 2007 at 11:01 UTC |