Multithreading 在Perl中,当另一个子进程正在运行时,我无法加入线程,该子进程是使用open分叉的

Multithreading 在Perl中,当另一个子进程正在运行时,我无法加入线程,该子进程是使用open分叉的,multithreading,perl,join,pipe,Multithreading,Perl,Join,Pipe,我想从主线程/进程执行以下操作: 使用管道与另一个进程通信 创建线程以执行特定任务 等待所有线程完成 以下是我正在尝试的伪代码: use threads; use IO::Handle; sub dummy { print "\n!!!!". $$; return 0; } open($handle, "| cat -v") || die "Unable to open connection to BT Driver: $!\n"; $handle->

我想从主线程/进程执行以下操作:

  • 使用管道与另一个进程通信

  • 创建线程以执行特定任务

  • 等待所有线程完成

  • 以下是我正在尝试的伪代码:

     use threads;
     use IO::Handle;
     sub dummy {
          print "\n!!!!". $$;
          return 0;
     }
    
     open($handle, "| cat -v") || die "Unable to open connection to BT Driver: $!\n";
    
     $handle->autoflush(1);
    
     #close $handle; If I uncomment this, threads can be joined. But I don't want to terminate this child process.
    
     $thr2 = threads->create(\&dummy);
     sleep 2;
     print "\n$thr2";
     foreach $thr (threads->list(threads::joinable))
     {
          print "\nIam here";
          print "\n!!!". $thr;
          $thr->join();
     }
    
    当我尝试连接线程时,代码会被卡住,即使它是可连接的

    我在这里犯了什么根本性的错误吗?
    我使用的是Perl 5.10.0,我没有编译线程的5.10.0,但是5.12.4挂起在“Iam here”。5.14.1运行至完工


    Perl线程有很多bug,但近年来它变得更好了。5.10.0可能会充满bug,而解决它(以及许多问题)的最简单方法就是升级Perl。

    我没有一个5.10.0版本,但5.12.4挂起在“Iam here”。5.14.1运行至完工


    Perl线程有很多bug,但近年来它变得更好了。5.10.0可能会充满bug,解决它(以及许多问题)的最简单方法就是升级Perl。

    你说的“卡住”是什么意思?到底发生了什么?我所说的卡住是指程序没有终止或更进一步$thr->join调用阻止代码。如果我删除连接调用,程序将退出1个活动的完成的未连接线程。我得到以下输出:[root@pe-lt154~]#perl线程_trial.pl!!!!9441线程=标量(0x9dbfed0)Iam此处“卡住”是什么意思?到底发生了什么?我所说的卡住是指程序没有终止或更进一步$thr->join调用阻止代码。如果我删除连接调用,程序将退出1个活动的完成的未连接线程。我得到以下输出:[root@pe-lt154~]#perl线程_trial.pl!!!!9441线程=标量(0x9dbfed0)Iam