threads on XP-- system() works, backtic & popen dosen't...

K

kdd21

Am running ActiveState perl v5.8.7 on Windows XP Pro. Tried the
following test script. The idea here is to run two parallel threads
that process a common queue of todo items. The processing however,
requires running some external executables. Had first tried the
backtic as I'd like to get the output. Was hanging so I tried some
other combinations.

Finally arrived at the following test script. I can run it on Debian
Linux (using the appropriate $XTCMD definition uncommented) and all
three flavors work fine, and pretty much identically.

On windows however, only $EXEMODE = 0 works. The others both hang on
the external.

I'd really like to avoid the temporary file technique, and use EITHER
the backtic or the popen version (or something else that would work if
I'm not aware of it)...

Any idea what's happening here? Windows pseudo-fork anomalies perhaps?
Any other alternatives?


#!/usr/bin/perl -w
use strict;
use threads;
use threads::shared;

my $EXEMODE = 0; # 0: system 1: bactic 2: popen Try all three to
compare

#my $XTCMD = "/usr/bin/sort testfile"; # linux test
my $XTCMD = "c:\\windows\\system32\\sort.exe testfile"; # windows test

my $queueindex : shared;
share $queueindex;

my $thearg = 0;
my $qsize = 10;
$queueindex = 0;

sub inc_qindex
{
# print "Locking index\n";
lock $queueindex;
$queueindex++;
# print "Returning index $queueindex\n";
return $queueindex;
}

sub dothread
{
my ($v,$m,@m);
my $taskctr = 0;
my $tmpfile = "tmp" . $thearg . ".out";
while (1)
{
$v = &inc_qindex; # get next queue item

last if ($v > $qsize); # end of queue

print "I am thread [" . $thearg . "] index = [" . $v . "]\n";

if ($EXEMODE eq 0) # this works OK
{
system("$XTCMD >$tmpfile");
open XT,"$tmpfile" or die "$!: Can't open $tmpfile!";
@m = (<XT>);
close XT;
$m = join("",@m);
print $m; # will see this
}

if ($EXEMODE eq 1) # this hangs
{
$m = `$XTCMD`;
print $m; # never see this
}

if ($EXEMODE eq 2) # this also hangs
{
open XT,"$XTCMD|" or die "$!: trying to run $XTCMD!";
@m = (<XT>);
close XT;
$m = join("",@m);
print $m; # never see this
}
$taskctr++;
}
return $taskctr;
}

sub test_threaded
{
my ($ta,$tb,$r);
$thearg = 1;
$ta = threads->new("dothread");

$thearg = 2;
$tb = threads->new("dothread");

$r = $ta->join;

print "Thread 1 returned [$r]\n";

$r = $tb->join;

print "Thread 2 returned [$r]\n";

}

#dothread; # test it unthreaded to make sure it works

test_threaded;
 
Z

zentara

On windows however, only $EXEMODE = 0 works. The others both hang on
the external.
Any idea what's happening here? Windows pseudo-fork anomalies perhaps?
Any other alternatives?

In case you don't find an answer here:

You might want to ask this on http://perlmonks.org
An active monk named BrowserUk is especially good at threads on Win32.
 
K

kdd21

zentara said:
In case you don't find an answer here:

You might want to ask this on http://perlmonks.org
An active monk named BrowserUk is especially good at threads on Win32.


Ok, just posted it there. I'd also figured I'd try the ActiveState
site forums, but have been having trouble getting anything to show up
there-- looks like it's all moderated and the moderators are apparently
indisposed. Though frankly, I hate proprietary forum systems, usenet
has been working fine for that purpose for over 20 years now, and it
ain't broke as far as I'm concerned...
 
R

robic0

Ok, just posted it there. I'd also figured I'd try the ActiveState
site forums, but have been having trouble getting anything to show up
there-- looks like it's all moderated and the moderators are apparently
indisposed. Though frankly, I hate proprietary forum systems, usenet
has been working fine for that purpose for over 20 years now, and it
ain't broke as far as I'm concerned...

Jesus H Christ, go back to PORN where you came from.........
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top