This problem appears to be intermittent.  Several people reported trying the
test and not having any problems.  So, I tried it on a second machine with
AS817, which, like my orignal machine was a 2.8GHZ hyperthreading box
(though it was AS813).  Thinking that hyperthreading might be the problem I
disabled it in the BIOS.  Still happens, but not all the time.  I looped the
test and within a minute or so it will hang as well.  Looks like some kind
of timing or race problem.  At the moment, system() is the only means of
running an external executable that appears to be thread-safe.  Now using a
streamlined version of the test program as contributed on the perlmonks site
with some minor modifications by me:


<code>
#! perl -slw
use strict;
use threads;

sub test {
        my $t = shift;

        my $cmd = "c:/windows/system32/sort.exe test$t.dat";

        # kludge to insure all threads are up (likely not necessary)
        sleep 1;

        system "$cmd >sorted$t.dat";

        open F, "<sorted$t.dat" or die $!;
        print "Via system:\n", do{ local $/; <F> };
        close F;
        
        print "Via backticks\n", `$cmd`;

        open F, "$cmd|" or die $!;
        print "Via pipe\n", <F>;
        close F;
}

my $t1 = async{ \&test(1); };
my $t2 = async{ \&test(2); };
my $t3 = async{ \&test(3); };
my $t4 = async{ \&test(4); };

$t1->join;
$t2->join;
$t3->join;
$t4->join;

</code>

I run this in the following .bat file:


:LOOP
perl threadtest.pl
goto LOOP


and if it doesn't hang right away usually will within a couple dozen
iterations, at least on two 2.8GHZ XP machines I've tried it on so far.  If
only the system() portion is included, I've yet to see it hang, only the
popen & backtic portions seem to be a problem.


--

Sync
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to