in reply to Re^3: "Thread already joined at..." and "A thread exited while x threads were running" errors
in thread "Thread already joined at..." and "A thread exited while x threads were running" errors

Hi again,

I'm using version 5.8.4, so hopefully I'm not experiencing a bug in Perl.

I'm trying to find a way of doing a hash that retains its order. I've looked on CPAN as you suggested, but both Tie::Hash::Indexed and Tie::InsertOrderHash which look suitable require compilation, and I was hoping to find something that could be copied from one platform to the other without any additional work (we have an old Python script which is very easy to use, and I want to at least equal that in terms of ease of use).

As for your final point about whether this is a worth while exercise, I have been told that it is as we need to be able to be able to compare our system when running on machines with different processors and operating systems, so issues like scheduling etc are one of the variables we need to look at. Hopefully by running the test many times we can get an average figure which reflects platform performance reasonably well.

I've given up on using batch files - they were worse than our script interpreter, as they were crashing the command prompt window (isn't Windows great). I'm now running some tiny exes I've just compiled in C that just printf() a character but the script still hangs. Here's the script so far:

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; # Change this structure accordingly... my %allScripts = ( submitters => { numRuns => 4, steps => ["print1.exe", "print2.exe"] }, reviewers => { numRuns => 1, steps => ["printA.exe", "printB.exe"] } ); my $numCompleteTestRuns = 4; my $mscriptInterpreter = "ScriptRunner.exe"; my $currentDir = getcwd(); eval{timethis($numCompleteTestRuns, 'runTests')}; warn $@ if $@; 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"); my @threadList = (); # 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 = $mscriptInterpreter . " \"" . $currentDir . "/ +" . $fileName . "\"\n"; my $command = $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"); }
  • Comment on Re^4: "Thread already joined at..." and "A thread exited while x threads were running" errors
  • Download Code

Replies are listed 'Best First'.
Re^5: "Thread already joined at..." and "A thread exited while x threads were running" errors
by BrowserUk (Patriarch) on Sep 07, 2004 at 12:40 UTC
    I'm trying to find a way of doing a hash that retains its order.

    Try Tie::IxHash; it's a pure perl module.

    I cannot reproduce your crashes. Try this slightly re-formatted version of your program and see if you still get problems. I've used some perl one-liners as the scripts to run which ought to be a pretty good simulation of your script processor.

    The output I got:

    I still have my doubts as the effectiveness as your mostly timing how long it tales to spawn threads and processes here--but you can make your own mind up on that:)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
      "Try Tie::IxHash; it's a pure perl module."

      Thanks for the advice, I'll look at that...

      "I cannot reproduce your crashes."

      Damn. I've just run your code and I still get the same problem. What platform are you using? (I'm on Win2k)

        That was XP/ActiveState 810, and I get the same results with my home-built 5.8.5.

        P:\test>perl -v This is perl, v5.8.4 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 810 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Jun 1 2004 11:52:21

        I'm not sure what to suggest. There is no obvious reason why 2K would be the cause of failure.

        Post the -V (not -v as above) from your copy of perl...maybe something will show up?


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon