Here is some working Win32 thread code that you can start from:
use strict; use threads; my @MyThread; my $threadcount = 15; for (0..($threadcount-1)){ $MyThread[$_]=threads->new(\&s,$_,10+$_); }; if ($ARGV[0] eq 'a'){ foreach (@MyThread){ print qq(Return check via thread array from ) . $_->join() . qq(\n +); } }else{ foreach (threads->list()){ print qq(Return check via threads list from ) . $_->join() . qq(\n +); } } ####################### sub s{ my $a=shift; sleep($threadcount-$a); print qq(In sub s param=$a\n); return shift() }
ANd some code that does something semi-useful with threads ..
use strict; use threads; use Thread::Queue; use Net::Ping; my $ThreadCount = 12; my @Threads; my $ServerQueue = Thread::Queue->new; my $ResultQ = Thread::Queue->new; my @Servers; # Replace the 4.2.2 with your subnet ... push @Servers, qq(4.2.2.$_) for (1..254); foreach my $Item (@Servers) { $ServerQueue->enqueue($Item); } for (1..$ThreadCount) { my $Thread = threads->new(\&Process, $ServerQueue); push (@Threads, $Thread); } foreach my $Thread (@Threads) { $Thread->join(); } print "\n--results---\n"; while (my $target = $ResultQ->dequeue_nb){ print " $target\n"; } ##################################### sub Process { my $ServerQueue = shift; my $pingobj = Net::Ping->new("icmp",5,100); while (my $Server = $ServerQueue->dequeue_nb()) { if ($pingobj->ping($Server)) { #ping was good $ResultQ->enqueue ($Server); threads->yield(); } else { #ping was bad } } }

Offense, like beauty, is in the eye of the beholder, and a fantasy.
By guaranteeing freedom of expression, the First Amendment also guarntees offense.

In reply to Re: perl ithreads join help!! by NetWallah
in thread perl ithreads join help!! by kcella

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.