On 2007-02-13 14:35:40 -0800, [EMAIL PROTECTED] (Nathan Vander Wilt) said:
I have a list of data that I want to operate concurrently on, as many threads as I have processors. So I wrote a bit of code that uses a semaphore to halt spawning of new threads when the limit are already running. I have two problems with the following code. First of all, it "dead"blocks on '$available->down()', since the thread apparently gets a copy of the semaphore (I've tried 'my $available :shared=...' and variations, with no change). How can I get my threads to up() the semaphore before returning?
Found out my Camel book didn't have the latest thread info, so switched to 'use threads;' and that solved this first problem.
Secondly, after each thread returns I get a "Scalars leaked: 1" internal Perl error on the console. Is this a sign that I'm doing something unwelcome? How do I get it to stop leaking scalars?
This seems to be related to the '$t->detach()', which I'm using because I don't care about the return value, am having trouble with growing memory usage, and I thought telling perl would help it out. (This happens on both 5.8.0 and 5.8.6.)
-nvw
thanks, -natevw ========== #!/usr/bin/perl use warnings; use Thread qw(async); use Thread::Semaphore; use Data::Dumper; sub tothread { print "$_[0]\n"; sleep(1); } doThreads(\&tothread,[10,9,8,7,6,5,4,3,2,1]); sub doThreads { my ($function,$values)[EMAIL PROTECTED]; my $processors=4; my $available=new Thread::Semaphore($processors); foreach my $val (@$values) { $available->down(); my $t = async { $function->($val); $available->up(); print "$available is ",Dumper($available); }; $t->detach(); } for (my $i=0; $i<$processors; $i++) { $available->down(); } } __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! Regístrate ya - http://correo.espanol.yahoo.com/
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/