gpt4 book ai didi

multithreading - 在Perl中,当运行使用open fork 的另一个子进程时,我无法加入线程

转载 作者:行者123 更新时间:2023-12-03 13:17:51 24 4
gpt4 key购买 nike

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

  • 使用管道与另一个进程通信。
  • 创建线程来执行某些任务。
  • 等待所有线程完成。

  • 以下是我正在尝试的伪代码:
     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卡在“我在这里”。 5.14.1运行完毕。

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

    关于multithreading - 在Perl中,当运行使用open fork 的另一个子进程时,我无法加入线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014969/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com