in reply to Thread::Queue and Memory

I think it is because the queue gets eaten too quickly..look at this:
#!/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 ; } }
cheers :0) JamesNC

Replies are listed 'Best First'.
Re: Re: Thread::Queue and Memory
by petesmiley (Friar) on Feb 20, 2003 at 22:21 UTC
    I'm not sure I understand what you are trying to show. I currently have a much larger sample of what I wrote. And it quite happily chews up memory with a full queue (more than 0). The queue always shows the correct size but for some reason it keeps eating more memory.

    The queue you have here would show the same problem I have when I analyze it under Devel::Leak I still see it allocating extra scalars every time it dequeues.

    Point being, my little piece of code does what my poor brain says will be just of few megs of ram. But instead it takes 80+.

      Ok, you were asking about the known memory leak in threads then?
      Perl Threads Leak
      If you think you know what's causing it, the threads author is mentioned in the link I believe. I don't know how many people are working on this, if you think you know enough to debug it, I am sure they would be very happy to let you have a go at it.