develooper Front page | perl.perl5.porters | Postings from May 2013

[perl #39531] Perl hangs when when using backticks or popen from a thread on Win32

From:
James E Keenan via RT
Date:
May 27, 2013 13:12
Subject:
[perl #39531] Perl hangs when when using backticks or popen from a thread on Win32
Message ID:
rt-3.6.HEAD-2650-1369660332-1887.39531-15-0@perl.org
On Mon Jun 19 09:51:24 2006, KDoyle@emdeon.com wrote:
> 
> This is a bug report for perl from kdoyle@emdeon.com,
> generated with the help of perlbug 1.35 running under perl v5.8.7.
> 
> 
> -----------------------------------------------------------------
> 
> Discovered that in ActiveState Perl build 813 & 817 will often hang when
> multiple threads are running that use either backtic or popen to
execute an
> external to capture the output.  Have reproduced it on 5 machines
in-house,
> and just received confirmation from the PerlMonk's site from another user
> whose been able to reproduce. Has been reproduced on Windows XP SP1 & SP2,
> and on single thread and multi-thread machines.
> 
> Some machines will hang immediately, some will require looping the test a
> few times, but on all machines tested the loop would produce a hang very
> quickly, within about a dozen iterations.  Also tested on Debian Linux,
> works without problems, so it appears to be unique to Windows.
> 
> 
> ===========example code follows: thread2.pl===============================
> #! perl -slw
> use strict;
> use threads;
> 
> sub test {
> 	my $t = shift;
> 
>         my $cmd = "c:/windows/system32/sort.exe test$t.dat";
> 
> 	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;
> }
> 
> 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;
> =====Test data file follows (all 4 test files are the same,
> test[1-4].dat=====
> world
> hello
> ===========Windows .bat file
> tester===========================================
> :LOOP
> perl thread2.pl
> goto LOOP
> =============================================================
> 
> 
> 
> The test program runs window's "sort" in four background threads to sort
> four test files. The path to Windows sort may differ on some machines
(some
> have a c:/winnt directory instead of c:/windows for example).  It doesn't
> matter what the background program is, sort was used because it was
> convenient to reproduce the problem with.  
> 
> Each of the threads test the three methods of executing external binaries,
> first with "system", then with backtic, and finally with popen.  If system
> is the only one used it won't hang, either backtic or popen will hang
if run
> by themselves.  Consequently, I'm currently using system as a workaround,
> but it's unfortunate that it requires additional disk I/O as in my
> application performance is important and disk I/O is a primary bottleneck.
> 
> 
> --
> 
> Keith Doyle
> 

In the course of reviewing older tickets this morning, I came across
this one.

Keith, were you ever able to resolve this problem?  Was the vendor with
whom you corresponded able to respond?

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=39531



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About