in reply to Reusable threads demo

Zentara,

Sorry to be "that guy", but you gave me the power, and with great power....should come jelly beans...or something like that.

Anyway, depending on what folks do with this code, there is a potential infinite loop here:
while (my $t = shift(@ready)){ $shash{$t}{'data'} = shift @to_be_processed; $shash{$t}{'go'} = 1; }

if you have enough threads that this loop isn't finished by the time the earliest threads are starting, then the worker will push threads back into the @ready list. In my case (as i just found out), it takes about ~130 threads to get to this point. Granted, in this example the loop will be done soon since the to be processed list is pretty short, but depending on what folks do with your example, this may not be the case. So, this probably isn't a general problem, but still.

Luckily, its easily solved (otherwise I'd be asking questions again). change the init loop to look like:

my @tready = @ready; @ready(); while (my $t = shift(@tready)){ $shash{$t}{'data'} = shift @to_be_processed; $shash{$t}{'go'} = 1; }

Hopefully this will be useful to the next madman that comes along

Replies are listed 'Best First'.
Re^2: Reusable threads demo
by zentara (Cardinal) on Aug 20, 2008 at 11:50 UTC
    We stand on the shoulders of the madmen who preceeded us, and hope they left us a stash of jellybeans. In reality, I would say that if you have an app hitting 130 threads, you may need a design adjustment, or switch to c. :-)

    I'm not really a human, but I play one on earth Remember How Lucky You Are