Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Reaped: beginner:pls finished the multiple thread port scanner scripts

by NodeReaper (Curate)
on Feb 18, 2013 at 09:48 UTC ( #1019307=perlquestion: print w/replies, xml ) Need Help??
NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

This node was taken out by the NodeReaper on Feb 18, 2013 at 18:46 UTC
Reason: [Mr. Muskrat]: REAP: Exact duplicate of the multiple thread port scanner scripts issue

You may view the original node and the consideration vote tally.

  • Comment on Reaped: beginner:pls finished the multiple thread port scanner scripts

Replies are listed 'Best First'.
Re: Reaped: beginner:pls finished the multiple thread port scanner scripts
by 7stud (Deacon) on Feb 18, 2013 at 19:27 UTC

    1)

    use strict; use warnings; use 5.012; use threads; use Thread::Queue; my $q = Thread::Queue->new; sub do_stuff { my $id = threads->tid; my $data; while ($data = $q->dequeue) { #Process data: sleep rand(5); say "$id: Done with: '$data'. ", 'Going back to q to get more data.'; } say "$id: No more data in q. Quitting..."; } my $max_threads = 5; my @threads = map { threads->create(\&do_stuff) } 1 .. $max_threads ; #All threads are now blocking on dequeue() and waiting for data. my @data = qw( hi hello greetings what where how world earth gia mars venus jupiter ); for my $data (@data) { $q->enqueue($data); } #Make all threads exit their while loops: for (1 .. $max_threads) { $q->enqueue(undef); } #Don't end the program until all threads have finished: for my $thr (@threads) { $thr->join } --output:-- 1: Done with: 'greetings'. Going back to q to get more data. 5: Done with: 'hello'. Going back to q to get more data. 3: Done with: 'what'. Going back to q to get more data. 5: Done with: 'world'. Going back to q to get more data. 5: Done with: 'earth'. Going back to q to get more data. 4: Done with: 'how'. Going back to q to get more data. 2: Done with: 'hi'. Going back to q to get more data. 1: Done with: 'where'. Going back to q to get more data. 1: No more data in q. Quitting... 5: Done with: 'mars'. Going back to q to get more data. 5: No more data in q. Quitting... 3: Done with: 'gia'. Going back to q to get more data. 3: No more data in q. Quitting... 4: Done with: 'venus'. Going back to q to get more data. 4: No more data in q. Quitting... 2: Done with: 'jupiter'. Going back to q to get more data. 2: No more data in q. Quitting...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019307]
help
Chatterbox?
[Corion]: I've started that again this month (now forever instead of a limited time), and it already destresses me a lot
[holli]: There are Anti Vaxxer weeks at IKEA.
[Corion]: Of course, it's a 20% cut in the money I receive, while the work doesn't necessarily reduce at all, but my approach is to make the work take longer instead of fitting 5 days worth of work into 4
[holli]: 50% off all children coffins.
[Corion]: holli: Ooof :)
[hippo]: Cut should beless than 20% after tax, though. :-)
[Corion]: hippo: Yeah, but at least two years ago, it still was close enough to 20% cut
[Corion]: But I have a very positive experience with a four day workweek and a three day weekend. I can't easily go back though to full money.
[Corion]: That is easy without having to pay for a house, a wife or children though. If I had any of these, or any two of these, the decision wouldn't be that easy.
[ambrus]: wait. I understand no wife and children, but how do you not have to pay for a house?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-09-21 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (249 votes). Check out past polls.

    Notices?