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.
In reply to Threads question by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |