P
Peng Yu
I have the following code. The there is a chance that the two print
line (with '#') may not function print consecutively. Is there a way
to lock so that I can guarantee they write consecutively?
$ cat main.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Parallel::ForkManager;
open OUT, ">main.txt";
my $pm = new Parallel::ForkManager(5);
foreach my $n (1..10) {
my $pid = $pm->start and next;
print $n, "\n";
sleep rand(1);
print OUT $n;#
print OUT $n;#
$pm->finish;
}
$pm->wait_all_children;
line (with '#') may not function print consecutively. Is there a way
to lock so that I can guarantee they write consecutively?
$ cat main.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Parallel::ForkManager;
open OUT, ">main.txt";
my $pm = new Parallel::ForkManager(5);
foreach my $n (1..10) {
my $pid = $pm->start and next;
print $n, "\n";
sleep rand(1);
print OUT $n;#
print OUT $n;#
$pm->finish;
}
$pm->wait_all_children;