nickos has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks!
I'm pretty new to Perl and am having problems with threads. I'm writing a benchmarking script that needs to create many different threads where each thread will run an external program (a script interpreter (not Perl) running different scripts) multiple times.
The script ends prematurely with the following errors:
Thread already joined at pm_spawn.pl line 72. A thread exited while x threads were running.and sometimes it seems to just hang randomly (and in different places). Any ideas what I'm doing wrong? I don't think the problem is from the external program, as the scripts that they're running simply print a character to the command line (for the moment anyway). I should probably add that I'm running Windows 2000.
Here's the script in it's entirety:
----------------EOF----------------use Acme::Comment type => 'C++', own_line => 1, one_line => 1; use Cwd; use Run; use Config; use Data::Dumper; use threads; //use Async; use Benchmark qw(:all); use strict; use warnings; $Config{useithreads} or die("Recompile Perl with threads to run this p +rogram."); # Change this structure accordingly... my %allScripts = ( submitters => { numRuns => 4, steps => ["tssubmitter_1.script", "tssubmitter_2.script"] }, reviewers => { numRuns => 1, steps => ["tsreviewer_1.script", "tsreviewer_2.script"] } ); my $numCompleteTestRuns = 100; my $scriptInterpreter = "ScriptRunner.exe"; my $currentDir = getcwd(); my @threadList = (); timethis($numCompleteTestRuns, 'runTests'); sub runTests { print "Waiting to spawn processes.\n"; foreach my $userType (sort {$allScripts{$a} <=> $allScripts{$b}} k +eys %allScripts) { // print Dumper($allScripts{$userType}{steps}); print "\nThe $userType will run $allScripts{$userType}{numRuns +} times. The steps are:\n"; foreach my $i (0 .. $#{ $allScripts{$userType}{steps}}) { print "$i = $allScripts{$userType}{steps}[$i]\n"; } } print("\n\n"); # key-value pairs in a Perl hash are not always stored in the orde +r in which they were defined! // foreach my $userType (keys %allScripts) foreach my $userType (sort {$allScripts{$a} <=> $allScripts{$b}} k +eys %allScripts) { for my $i (0 .. $allScripts{$userType}{numRuns}) { print "\nAbout to create $userType thread $i:\n"; my $thread = threads->new(\&stepThread, \$allScripts{$user +Type}); push (@threadList, $thread); } } my $numThreads = $#threadList + 1; print("There are $numThreads threads\n\n"); # wait for each running thread to end foreach my $thread (@threadList) { $thread->join; print("A thread joined\n\n"); } print "Processes ended - Goodbye.\n"; } # thread runs a type of users steps once only sub stepThread { print("starting thread\n\n"); my $currentUsertype = shift; // print Dumper(${$currentUsertype}->{steps}); foreach my $i (0 .. $#{${$currentUsertype}->{steps}}) { my $fileName = ${$currentUsertype}->{steps}[$i]; my $command = $scriptInterpreter . " \"" . $currentDir . "/" . + $fileName . "\"\n"; print("About to run: $fileName\n"); my $time0 = new Benchmark; my $output = `$command`; my $time1 = new Benchmark; my $timeTaken = timestr(timediff($time1, $time0)); my $printOutput = "******** BEGIN $fileName output ********\n$ +output\n******** END $fileName output (time taken: $timeTaken) ****** +**\n"; print($printOutput); } print("Ending thread\n\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "Thread already joined at..." and "A thread exited while x threads were running" errors
by PodMaster (Abbot) on Sep 06, 2004 at 13:29 UTC | |
|
Re: "Thread already joined at..." and "A thread exited while x threads were running" errors
by BrowserUk (Patriarch) on Sep 06, 2004 at 14:59 UTC | |
by nickos (Initiate) on Sep 06, 2004 at 15:44 UTC | |
by BrowserUk (Patriarch) on Sep 06, 2004 at 16:54 UTC | |
by nickos (Initiate) on Sep 07, 2004 at 09:54 UTC | |
by BrowserUk (Patriarch) on Sep 07, 2004 at 12:40 UTC | |
|