Hello monks,
I have a couple of questions about perl threads. I have read the available tutorials online and have searched google, but my questions still remain.
a) If I use an smp system on Linux, can I expect threads to run on different processors like kernel threads? How exactly is the determination made which processor which thread runs on?
b) I have the following logic that I would like to code. Is there anyone that can help turn it into valid perl code?:
Run 30 threads that continuously check the internet to see if an event is true. If it is, another 30 threads which have already been spawned immediately take action.
c) Is there any timing issues that you can see that I will run into?
Thanks in advance for your posts,
Brian
This code is so wrong :)
#!/usr/bin/perl -w
use threads; # threading routines
use threads::shared;
use Thread::Queue;
our $queue : shared = Thread::Queue->new;
for (1..30){
$thr = threads->new(\&thread_sub);
}
for (1..30) {
$thr1 = threads->new(\$thread_sub1);
}
$thr->join;
$thr1->join;
sub thread_sub {
while ($test == 0) {
if (certain test is true)
{$test = 1;}
}
#### Now here is where I am getting really god damned lost
{my $action = $queue->enqueue;}
}
sub thread_sub1 {
$action = $queue->dequeue; #??? totally lost here
print "I am going to do your bidding master now that the test is
+ true\n";
}
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.