in reply to Re^2: Queuing in multithread context
in thread Queuing in multithread context
Okay. Now you've shown us the sample config file, it shows that you are running each of multiple DEPLOY sections on each of the servers, each in a separate thread; hence your conflicts.
The simple solution to your problem is to only start one thread for each server; and call the deployRoutine() multiple times within that thread; serially.
Ie. Something like this:
foreach my $targetServer (@targets) { # Ping host to check its available my $p = Net::Ping->new(); if ($p->ping($targetServer)) { my @subs; ### Accumulate the deployRoutines here foreach my $deploySection (@deployments) { if ($flagDeploy) { my $deploySource = "$config{$deploySection}{'Source'}" ; my $deployDest = "$config{$deploySection}{'Destination'}" +; if ($flagNoMove) { ## Add this sub to the array to be executed for this s +erver push @subs, sub { deployRoutine($targetServer, $deploy +Source, $deployDest, "true") }; $threadDetails{$thread}{"Section"} = "$deploySection"; $threadDetails{$thread}{"Target"} = "$targetServer"; } else { ## Add this sub to the array to be executed for this s +erver push @subs, sub { deployRoutine( $targetServer, $deplo +ySource, $deployDest ) }; $threadDetails{$thread}{"Section"} = "$deploySection"; $threadDetails{$thread}{"Target"} = "$targetServer"; } } } ## Now start one thread to execute them all; serially push @threads, threads->new( sub { $_->() for @subs; } ); $p->close(); }
Note: That is obviously untested code in the context of your application, but in isolation, the principle works:
{ use threads; my @subs = map{ eval "sub{ print $_; }" } 1 .. 10; threads->new( sub{ $_->() for @subs; } ); sleep 10; };; 1 2 3 4 5 6 7 8 9 10
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Queuing in multithread context
by Hardin (Novice) on Jan 20, 2015 at 16:55 UTC | |
by BrowserUk (Patriarch) on Jan 20, 2015 at 18:26 UTC |