in reply to problem in queue implementation
It's waiting for more stuff to be added to the queue.
If the queue is preloaded and doesn't change, you could use dequeue_nb.
use strict; use warnings; use threads; use threads::shared; use Thread::Queue; my @ary :shared = qw( a b c ); my $q = Thread::Queue->new(); $q->enqueue(\@ary); while (my $ar1 = $q->dequeue_nb()) { print "array reference : $ar1\n@$ar1\n"; }
If data will be added to the queue once the threads have started, use a special value to indicate there is no more data forthcoming. undef would work fine if your queue otherwise contains arrays.
use strict; use warnings; use threads; use threads::shared; use Thread::Queue; my @ary :shared = qw( a b c ); my $q = Thread::Queue->new(); $q->enqueue(\@ary); $q->enqueue(undef); # One for each consumer. while (my $ar1 = $q->dequeue()) { print "array reference : $ar1\n@$ar1\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem in queue implementation
by rajj.nmt4 (Initiate) on Oct 15, 2009 at 06:38 UTC | |
by ikegami (Patriarch) on Oct 15, 2009 at 12:53 UTC |