Perl fork()子例程'free free to wrong pool'错误

时间:2013-12-05 12:11:02

标签: multithreading perl fork

我问了一个关于多线程的早期问题,我试图并行运行两个(类似的)子程序。大家一致认为虽然代码看起来没问题(使用线程),但我应该尝试使用fork()作为替代方案来查看问题是否消失。我看到的问题是perl解释器崩溃时出现“自由错误的池”错误。

该脚本试图同时在两个不同的手机上运行手动PLMN搜索,并报告两个手机何时完成。我同时扫描两个不同的adb logcat日志以在每个日志中搜索扫描完成的字符串,但是一旦在子例程dutmplmn中找到字符串,我就会收到“自由错误的池”错误。现在这是一个等待其他子程序正确完成的情况,还是我的子程序太过类似,以至于perl解释器无法应对?我认为第一个子程序完成并退出而不等待第二个子程序完全完成。此时代码失败>>取消链接($文件);出口;

我在Windows7上使用最新的草莓perl 5.18.1.1

这是fork()代码......

use strict;
use Win32::OLE;
use EFS_Handle;
use HelperFunctions;
use threads;
use warnings;

#### Various ADB command sequences follow ####
#### Start of multithread to run the same function on different android handsets ####

  my $file = new File::Temp( UNLINK => 0 );

  my $new_pid = fork();
  die "fork failed $!" unless defined $new_pid;   # this is uncommon

  # Task 1 - in the background
  if ($new_pid == 0) {
      dutmplmn();   
      unlink($file);
      exit;            
  }

  use POSIX ':sys_wait_h';
  while (! waitpid $new_pid, &WNOHANG) {   # WNOHANG => non-blocking wait
      refmplmn(); 
   }

  sub dutmplmn{

     open my $fh_DUT, '>', "output_DUT.txt" or die "Cannot open output_DUT.txt: $!";
     my $pid_DUT = open my $log_DUT, "-|", "adb -s 42d8d7dd logcat -b radio";

     sleep(2);

     print "\n\t" . DUTcurTime() . " :\t DUT Time at start of MPLMN search";
     system('adb -s 42d8d7dd shell input keyevent KEYCODE_ENTER');

     while(<$log_DUT>) {
      $fh_DUT->print($_);
      last if m/showPlmn='true'/;
     }
  kill "TERM", $pid_DUT;
  close $log_DUT;
  print "\n\t" . DUTcurTime() . " :\t DUT Time at End of MPLMN search\n";


  }

  sub refmplmn{       

     open my $fh_REF, '>', "output_REF.txt" or die "Cannot open output_REF.txt: $!";
     my $pid_REF = open my $log_REF, "-|", "adb -s 0123456789ABCDEF logcat";

     sleep(2);

     print "\n\t" . REFcurTime() . " :\t REF Time at start of MPLMN search";
     system('adb -s 0123456789ABCDEF shell input keyevent KEYCODE_ENTER');

     while(<$log_REF>) {
      $fh_REF->print($_);
      last if m/EVENT_NETWORK_SCAN_COMPLETED/;
     }
    kill "TERM", $pid_REF;
    close $log_REF;
    print "\n\t" . REFcurTime() . " :\t REF Time at End of MPLMN search\n";
  }

谢谢, MikG

0 个答案:

没有答案