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.
In reply to Re: Threads memory consumption
by Random_Walk
in thread Threads memory consumption
by mojo2405
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |