sub _replicate{ my $ref = shift; my $logger = get_logger(); print "Starting replication of dependency files", $/; foreach my $sc(@{$ref}){ next unless (defined $sc); mkdir($LOG_FOLDER."/".$sc->{sc_name}); print "\tScenario: ".$sc->{sc_name}, $/; print "\tLatest Dependencies: ".$sc->{total_dep}." of size "._get_readable_size($sc->{total_size}), $/; my @thr_arr = (); print "Creating parallel threads", $/; foreach my $robj(@{$sc->{rsync}}){ my $th = threads->create(\&worker, $robj); # i create threads this way push @thr_arr, $th; } #$logger->info("\twaiting for threads to finish its job..."); print "\twaiting for threads to finish its job...", $/; foreach my $t(@thr_arr){ if (defined $t){ my $k = $t->join(); # this is how i wait for all threads to finish } } #map {my $k = $_->join} threads->list; # map{ # my $th = $_; # my $k = $th->join if($th); # just a blind belief whether this might cause 'Segmentation fault', hence the check. # }@thr_arr; #$logger->info("\tFinished replicating dependencies of ".$sc->{sc_name}); print "\tFinished replicating dependencies of ".$sc->{sc_name}, $/; } } sub worker{ my $robj = shift; my ($rsync, $server, $from, $to) = @{$robj->{elements}}; my $alt_server = $RSYNC_CONN_STR_2; my $rsync_cmd = $rsync.$server.$from.$to; print "Thread-",threads->self->tid," executing ", $rsync_cmd; }