I am using threads module to execute 10 threads a a time. They are actually doing a curl to download a file (all 10 of them). Now, some times the curl fails and it returns an error code. This error code I want to capture and report. I cannot find how Threads returns me return/exit codes of a thread. Here is my code snippet:
my $count = 10;
my @threads = ();
for (1..$count) {
my $tid = threads->new(\&RunChild, $_);
push (@threads, $tid);
}
foreach (@threads) {
my $num = $_->join();
#Here I want to check return code of thread, so that I can report the
+error.
my $error = ????;
if ($error) {
print "Thread $num returned error $error\n";
} else {
print "Thread $num completed\n";
}
}
sub RunChild {
my $callNum = $_[0];
`curl -o $callNum "http://192.168.1.23/abc.flv"`
return $callNum;
}