Re: question about forked processes writing to the same file
- From: xhoster@xxxxxxxxx
- Date: 17 Oct 2005 03:37:21 GMT
"it_says_BALLS_on_your forehead" <simon.chao@xxxxxxx> wrote:
> it_says_BALLS_on_your forehead wrote:
> > is this dangerous? for instance, is there ever a danger of race
> > conditions/locking/etc if i have:
> >
> > use strict; use warnings;
> > use Parallel::ForkManager;
> >
> > my $pm = Parallel::ForkManager->new(10);
> >
> > # assume @files contains 100 files that will be processed,
> > # and processing time could range from subseconds to hours
> >
> > my $out = 'results.txt';
> > for my $file (@files) {
> > $pm->start and next;
> >
> > # some code to process file
> > # blah blah blah
> >
> > open( my $fh_out, '>', $out ) or die "can't open $out: $!\n";
>
> Apologies... ^^^ should be '>>'
>
> > print $fh_out "$file\n";
> > close $fh_out;
> >
> > $pm->finish;
> > }
> > $pm->wait_all_children;
On Linux this is safe, provided the string $file is not more than a few
hundred bytes. On Windows, it is not safe (although probably safe
enough, provided this is just for progress monitoring)
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- Follow-Ups:
- References:
- question about forked processes writing to the same file
- From: it_says_BALLS_on_your forehead
- Re: question about forked processes writing to the same file
- From: it_says_BALLS_on_your forehead
- question about forked processes writing to the same file
- Prev by Date: Re: question about forked processes writing to the same file
- Next by Date: Re: question about forked processes writing to the same file
- Previous by thread: Re: question about forked processes writing to the same file
- Next by thread: Re: question about forked processes writing to the same file
- Index(es):
Relevant Pages
|