Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Efficient way to fork processes and keep a running count?

by ikegami (Patriarch)
on Jan 27, 2010 at 20:27 UTC ( [id://820019]=note: print w/replies, xml ) Need Help??


in reply to Efficient way to fork processes and keep a running count?

use threads; use Thread::Queue qw( ); my $num_drives = 3; my $num_discs = 12; my $q = Thread::Queue->new(); $q->enqueue( 1..$num_discs ); $q->enqueue( (undef) x $num_drives ); for my $drive (1..$num_drives) { ... eject disc ... async { while (defined(my $disc = $q->dequeue())) { print("Please insert disc $disc in drive $drive\n"); ... wait for disc to be present ... ... read disc ... ... eject disc ... } }; } $_->join for threads->list();

Replies are listed 'Best First'.
Re^2: Efficient way to fork processes and keep a running count?
by bfreemer (Novice) on Jan 27, 2010 at 21:02 UTC
    Thanks much ikegami for the quick reply and code example. I'll do some reading now and play with your code to learn a little. Thanks again for the example!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-25 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found