Re: question about forked processes writing to the same file



"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
.



Relevant Pages

  • Re: question about forked processes writing to the same file
    ... is there ever a danger of race ... > use strict; use warnings; ... > # and processing time could range from subseconds to hours ... > # blah blah blah ...
    (comp.lang.perl.misc)
  • Re: mobile phones whilst cycling?
    ... competent rider'. ... the move becasue part of that being a safe and competent cyclist is ... Anticipation and context are key. ... And danger is about the risk and severity of such outcomes. ...
    (uk.rec.cycling)
  • Re: What would it take for the Police take action.
    ... be safe to overtake unless you cross them, which in itself would be dangerous and also an offense. ... And apparently not of the distance between you and the overtaking vehicle ... others in danger without any danger of being prosecuted and there is nothing that the victims can legally do about this. ... It's all a question of distances, closing speeds, etc. ...
    (uk.rec.cycling)
  • Re: Boat Heating revisited
    ... electrickery and know what to do with it to make it safe. ... It's a danger, not only to the owner who does it, but to the ... does a job on my gas/oil I want to be watching him do it and be able to ask ...
    (uk.rec.waterways)
  • Re: Why flashing headlights is poor driving.
    ... you are working in a professional environment, ... Before proceeding, I make my own mind up if I can proceed safely. ... Any good driver will only proceed when they themselves have confirmed it is safe to continue. ... How many times have you had to ignore the HC to get out of danger of something? ...
    (uk.rec.driving)