Multithreading

From RAJ INFO
Revision as of 16:48, 8 January 2010 by Raj (talk | contribs) (Created page with 'This is really cool tool * Install the Library '''Parallel::ForkManager''' through CPAN * It works only in a loop (of anykind). so make a loop if you don't have one * code as be…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is really cool tool

  • Install the Library Parallel::ForkManager through CPAN
  • It works only in a loop (of anykind). so make a loop if you don't have one
  • code as below
# Libraries
	use Parallel::ForkManager;

# My Variables
       my $pm = new Parallel::ForkManager(4); # 4 is the number of cores in your processor


# Loop

	foreach my $file(@files) {
		$i++;
		$pm->start and next;
                # Do your bog process
		$pm->finish;
	}
	$pm->wait_all_children;

# END