perl - Why don't I see race conditions when my processes are writing to file? -


i use parallel::forkmanager module fetching pages. below relevant code snippet:

use parallel::forkmanager;  open file,">myfile" or die "cann't open file$!"; $pm = new parallel::forkmanager(5);  foreach $data (@all_data) {      $pid = $pm->start , next;     #doing fetching here , result on parsed_string      print file $parsed_string;     $pm->finish; # terminates child process } 

could expain why results ok , don't overlap 1 other there more 1 process writing same file ?

give race. printing single line doesn't create resource contention. output program more of expect?

use parallel::forkmanager;  open file, '>', 'myfile' or die "cann't open file$!"; select file; $|++;  $pm = parallel::forkmanager->new(5);  foreach $data ( 0 .. 100 ) {     $pid = $pm->start , next;     #doing fetching here , result on parsed_string      print file "1. ";     sleep 1;     print file "printing ";     sleep int( rand 3 );     print file "$$\n";     sleep int( rand 5 );     print file "2. print";     sleep int( rand 2 );     print file "ing $$\n";     $pm->finish; } 

i got:

1. 1. 1. 1. 1. printing 7515 printing printing 7517 printing printing 7519 2. print7518 2. print7516 ing 7517 1. ing 7515 2. printing 7519 1. printing 1. printing 7520 2. printprinting 7522 2. print2. print7521 ing 7520 1. ing 7516 ing 7518 1. 2. print1. 2. printing 7522 1. printing printing ing 7521 printing 1. printing 7527 7524 2. print7525 2. printing 7525 7526 1. printing ing 7524 1. 2. print  

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -