in reply to Re: Behavior of threads on XP-- system() works, backtic & popen don't...
in thread Behavior of threads on XP-- system() works, backtic & popen don't...
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Behavior of threads on XP-- system() works, backtic & popen don't...
by BrowserUk (Patriarch) on Jun 14, 2006 at 17:48 UTC | |
by Sync (Initiate) on Jun 15, 2006 at 16:49 UTC | |
by BrowserUk (Patriarch) on Jun 16, 2006 at 12:15 UTC | |
by Sync (Initiate) on Jun 16, 2006 at 17:23 UTC | |
by BrowserUk (Patriarch) on Jun 16, 2006 at 18:04 UTC | |
| |
by ww (Archbishop) on Jun 16, 2006 at 18:29 UTC | |
|