我有一个多线程的主 Perl 脚本。我想要做的是每个线程将运行 3 个命令,一旦整个线程完成,我希望我的脚本再次触发同一个线程,基本上是在一个循环中,谁能告诉我该怎么做
这是我的perl 代码片段
my @finalOneClickarray= grep(/\S/, @oneclickConcurrentbackup); #----Removing the empty content from the array---#
#---Making Concurrent OneClick backup commands using threads------#
my @threads;
#-----performing the CHO loops as given by user-------#
foreach (@finalOneClickarray) {
push @threads, threads->new(\&concurrentBackupCommandsRead, $_);
}
foreach (@threads) {
$_->join();
}
concurrentBackupCommandsRead是执行命令的方法。
更新的 perl 代码:-
use threads;
use threads::shared;
my @arr = (1,2,3,4);
my $outnumber :shared =4;
print "\n variable outside thread that is in main program $outnumber\n";
my @threads;
for($i=0;$i<=3; $i++)
{
print "\ncalling subrountine vinay for $i times\n";
vinay();
}
sub vinay()
{
foreach (@arr) {
push @threads, threads->create(\&doSomething);
}
foreach (@threads) {
$_->join();
}
}
sub doSomething ()
{
print "\n Before increment is $outnumber\n";
my $foo = $outnumber;
$outnumber = $foo + 1;
print "\n After increment is $outnumber\n";
}