Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Reusable threads demo

by JoeKamel (Acolyte)
on Aug 19, 2008 at 19:32 UTC ( [id://705317]=note: print w/replies, xml ) Need Help??


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 (Archbishop) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://705317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found