I don't know about smp distributing threads, I guess the kernel will decide? But here are some general comments on threads.
When joining, the thread must return from it's code block, either by reaching the end of the block, or with an explicit return.
# bad, you are only joining 1
# $thr->join;
# $thr1->join;
#better
foreach my $thread ( threads->list ) {
+
$thread->join;
+
}
# or you could stuuff the threads into hashes
# like
my %thrs;
for(1..30){
$thrs{$_}{'thread'} = threads->new(\&thread_sub);
}
#then join them by looping thru the hash keys
You are probably going to need to use shared variables
to control interaction between the threads, but I'm not very familiar with enqueue
sub thread_sub {
while ($test == 0) {
if (certain test is true)
{
$test = 1; #maybe test should be shared
return;
}
}
# Now here is where I am getting really god damned lost
{my $action = $queue->enqueue;}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.