Interesting. A couple of things:

First, thanks for the response.

Second, it took me some effort to find your response as I had posted the original to "seekers of perl wisdom" but never actually saw it show up anywhere except when I login and look at my "Nodes You Wrote." I finally did a "super search" of everything for "threads XP" in the title and finally discovered your reply-- I still don't know where this discussion thread is actually showing up, as the "super search" didn't seem to tell me *where* it found what it found...

And finally, I'm using AS 813, and your example works for me too. However, what it doesn't do is run multiple threads in parallel-- it just runs a single thread. So, I tweaked it a bit and came up with the attached version of your program. I was running into errors due to sort not being able to access the test.dat file in each thread due to collisions, so I created 4 copies of the test.dat file (test1-4.dat) and also use the scheme for the sorted.dat output file so that the threads won't be using each others files. I then run async 4 times to spawn off 4 threads. I also added a sleep in the thread (probably not necessary) to make sure all 4 threads are running before any of them start doing their thing. After that, the first thread's system() call works, and then the whole thing hangs. If I only run one thread in "spawnem" then it works OK...

#! 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;

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.