in reply to Re^2: Queuing in multithread context
in thread Queuing in multithread context
This is a very basic representation of how your threading model might look:
use 5.16.2; use threads; use Thread::Queue; my @serverList = qw(one two three four five six); my $serverQueue = Thread::Queue->new( @serverList ); $serverQueue->end; my @threads = map { threads->new( \&worker ) } 1..4; $_->join for @threads; say 'Back to main - Finished!'; sub worker { my $tid = threads->tid; while ( my $server = $serverQueue->dequeue_nb ) { say "I'm thread ID $tid and I'm processing server $server to c +opy a whole bunch of files"; sleep 1; } say "Thread ID $tid finished"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Queuing in multithread context
by Hardin (Novice) on Jan 20, 2015 at 16:37 UTC | |
by SimonPratt (Friar) on Jan 20, 2015 at 18:39 UTC |