in reply to Re^5: Behavior of threads on XP-- system() works, backtic & popen don't...
in thread Behavior of threads on XP-- system() works, backtic & popen don't...

Well, I don't know what to say at this point-- so far I've tried it on FIVE different machines of various sorts, all XP but both SP1 & SP2, hyperthreading and not, laptops and desktops, Intel & AMD CPUs, from 866MHZ to 2.8GHZ, and they all readily exhibit the problem. I can come up to a machine, install the AS817 .msi with all the default installation options, then open a dos window and run the .bat test loop above and it will hang in short order, sometimes immediately but always within a small number of iterations. I've yet to find a machine where it DOESN'T happen. I'm running out of machines to test it on... -- Sync
  • Comment on Re^6: Behavior of threads on XP-- system() works, backtic & popen don't...

Replies are listed 'Best First'.
Re^7: Behavior of threads on XP-- system() works, backtic & popen don't...
by BrowserUk (Patriarch) on Jun 16, 2006 at 18:04 UTC

    Perhaps if you posted the exact code that you are testing with, rather than a vague description of a vague starting point, then I might see why my attempts to reproduce your code from your descriptions doesn't hang and yours does.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      The exact code is in Re:^2.

      But to be even more exact, the data I put in the test dat files is exactly two lines:

      world
      hello

      Though I tried a 1-9 approach as you did in Re:^3 and it didn't change the result. And the exact .bat script for looping the test until it hangs is also in Re:^2:

      LOOP: perl thread2.pl goto LOOP

      On 3 out of 5 machines I tried it hangs immediately just after the first output of the system() results of the threads, on the other two machines it loops a few times then hangs at various points. On those machines it takes less than 60 seconds to produce a hang. -- Sync

        And the exact .bat script for looping the test ...

        Um. Not quite.

        c:\test>555304 c:\test>LOOP: 'LOOP:' is not recognized as an internal or external comm operable program or batch file. c:\test>perl 555304.pl Thread 1 Thread 2 Thread 3 Thread 4 Via system: hello world Via system: hello world Via system: hello world Via system: hello world Via backticks hello world Via backticks hello world Via backticks hello world Via backticks hello world Via pipe hello world Via pipe hello world Via pipe hello world Via pipe hello world c:\test>goto LOOP The system cannot find the batch label specified - LOOP

        The syntax should be (note the placement of the colon ':' in the first line):

        :LOOP perl 555304.pl goto LOOP

        However, having corrected that, I did manage to reproduce the hang. I don't know the cause, but at least I have something to work with. You should probably raise a perlbug so that the p5p guys can see what they can see.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^7: Behavior of threads on XP-- system() works, backtic & popen don't...
by ww (Archbishop) on Jun 16, 2006 at 18:29 UTC
    update Overtaken by OP's additional info in thread above. NO <strike>...</strike> as the observation may tickle a neuron in another monk, someday.
    Given BrowserUK 's yeoman attempts to help you, you might consider that the known, common factor on all five machines is the code you wrote. That, it seems to me, makes it worthwhile to check that code carefully... and to be sure what you showing in your OP is still relevant.

      I appreciate that BrowserUK is attempting to help, I'm not knocking that at all (yes-- thank you VERY MUCH BrowserUK). As I just posted in my reply to him-- the Re^2 code is exactly what I'm using to test with:

      #! perl -slw use strict; use threads; sub test { my $t = shift; my $cmd = "c:/windows/system32/sort.exe test$t.dat"; print "Thread $t\n"; # show things are in motion... sleep 1; # kludge to insure all threads are up... 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; } sub spawnem { 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; } &spawnem;

      The test1-4.dat files all contain the same two lines

      world
      hello

      And I loop the test from the DOS shell with the following .bat script:

      LOOP: perl thread2.pl goto LOOP

      A typical output I get when it hangs immediately looks like this:

      Thread 1 Thread 2 Thread 3 Thread 4 Via system: hello world

      where it just sits there and hangs until I ctl-C.

      It'd be nice if the problem is a bug in my code, but I had started originally with a larger example and BrowserUK neatly reduced it to a short little thing that worked for him but didn't run multiple threads in parallel. So I modified it so that it would and that's where the code came from. Again, I may have introduced a bug and if so I'd sure like to know where my conception of how threads works is faulty...

      -- Sync