aravind_v21 has asked for the wisdom of the Perl Monks concerning the following question:
The above is a model of my code. The first sub is called which in turns call the second sub(the parent thread). The second sub in turn creates 5 other child threads. I call sub1 and then sub2 for each thread.use strict; use diagnostics; use threads; my @array_of_threads; my $i =0; my $string; sub first{ print "called first"; &second();} sub second { ## creating 5 threads for ($i ; $i<5;$i++) { $array_of_threads[$i]=threads->new(\&sub1,"$i"); print "End of thread ".int($i+1)." creation\n"; } &complete(); } sub complete{ print "The threads have completed the execution\n";} sub sub1{ my $j=$_[0]; print "Thread $j has entered sub1\n"; &sub2($j);} sub sub2{ my $k= shift; ## loop for thread 3 to show that time for processing the threads +maybe different if($k==3) { for (my $in=0;$in<500;$in++){ print "Thread $k has entered sub2 --- $in\n"; }} } &first();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to use threads for this problem?
by BrowserUk (Patriarch) on Apr 26, 2007 at 07:30 UTC | |
|
Re: how to use threads for this problem?
by quester (Vicar) on Apr 26, 2007 at 07:42 UTC | |
|
Re: how to use threads for this problem?
by BrowserUk (Patriarch) on Apr 26, 2007 at 08:15 UTC |