in reply to Threads memory consumption
something along these lines may get you started...
use strict; use warnings; use threads; use Thread::Queue; my $wq = Thread::Queue->new(); # Build a queue where you put work my $thread_limit = 4; # how many threads do you want? my @thr = map { # create threads and store the handles in @thr threads->create( sub { while (my $item = $wq->dequeue()) { # finish when undef # Do something with item } } ); } 1..$thread_limit; while (I get $data to process) { $wq->enqueue($data); } # Tell the threads we are done $wq->enqueue(undef) for @thr; # Wait for all the threads to finish $_->join() for @thr;
Now go and read the docco for Threads and Thread::Queue. Its pretty good.
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Threads memory consumption
by mojo2405 (Acolyte) on Dec 05, 2013 at 09:55 UTC | |
by Random_Walk (Prior) on Dec 05, 2013 at 11:21 UTC |