in reply to Thread::Queue and Memory
cheers :0) JamesNC#!/perl/bin/perl use strict; use threads; use Thread::Queue; my @threads; my $thread; my $q = Thread::Queue->new(); $q->enqueue(1..100); print "Items in the queue: ",$q->pending,"\n"; for (1..5) { push @threads, threads->new(\&ttest); print "spawned thread:"; } foreach $thread (@threads){ $thread->join; } sub ttest { while (my $cnt = $q->pending) { my $item = $q->dequeue; print "$cnt\n"; last if $cnt == 0 ; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Thread::Queue and Memory
by petesmiley (Friar) on Feb 20, 2003 at 22:21 UTC | |
by JamesNC (Chaplain) on Feb 24, 2003 at 14:32 UTC |