SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Thread: Multi Threading

  1. #1
    SitePoint Addict
    Join Date
    Jun 2008
    0 Post(s)
    0 Thread(s)

    Multi Threading


    This code is based on creating the forking process. The problem is some of the files are written to the log file while reading a directory.
    How can I change to multi-threading and write the read files to a log file using locking concept using thread.
    or How can I use any kind of IPC for logging from all the spawned process which sends the back the message to main process for logging
    Please help me..

      my $pm = new Parallel::ForkManager($tc+1);
        $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; $tmp[$ident] = undef; } );
        foreach my $i (0..$#tmp) {
          # Forks and returns the pid for the child:
          my $pid = $pm->start($i) and next;
          $SIG{INT} = 'DEFAULT';
          my $filename = $tmp[$i]->filename();
          my $file = IO::File->new("<$filename") or die "Can't open $filename\n";
          while((my $line) = $file->getline()) {
            last unless defined($line);
            my ($dir, $file) = split(/\t/, $line);
          $pm->finish; # Terminates the child process
    Thanks in advance
    Last edited by sandy1028; Apr 20, 2009 at 23:32.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts