I want to do following things from main thread/process:
-
Communicate to another process using pipe.
-
Create threads to do certain task.
-
Wait for all the threads to complete.
Following is the pseudo code I am trying:
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();
}
Code gets stuck when I try to join the thread even though it is joinable.
Am I doing something fundamentally wrong here?
I am using Perl 5.10.0
I don’t have a 5.10.0 with threads compiled to try it, but 5.12.4 hangs at “Iam here”. 5.14.1 runs to completion.
Perl threads have a lot of bugs, but it’s gotten much better in recent years. 5.10.0 is probably going to be full of bugs and the simplest way to solve it (and a lot of problems) is to just upgrade Perl.