hey guys i have written a simple perl script to test the perl threading ability as follow, you can see i span 3 threads each simply sleeps for 20 secs. but i end up seeing 5 indentical PROCESSES running in my box, those are supposingly threads now ended up as forked children and i really have no idea why....
the cose itself
============================================
#!/usr/bin/perl
use Config;
$Config{useithreads} || die "Recompile Perl with threads to run this p
+rogram.";
use threads;
#use threads::shared;
#use Thread::Running;
#use Thread::Signal;
#use Thread::Queue;
sub ithread
{
my $i;
my $arg=shift||'';
print "just received - $arg\n";
foreach(1...20)
{
print $i++, "\n";
sleep(1);
}
}
foreach(1...3)
{
my $thread = threads->create( "ithread", "arg" );
}
foreach(1...30)
{
sleep(1);
print "running..\n";
}
exit;
==========================================
output of ps -aux
============================================
root 12882 1.0 0.0 11752 3504 pts/0 S 21:07 0:00 /usr/bin/perl /root/threads.pl
root 12885 0.0 0.0 11752 3504 pts/0 S 21:07 0:00 /usr/bin/perl /root/threads.pl
root 12886 0.0 0.0 11752 3504 pts/0 S 21:07 0:00 /usr/bin/perl /root/threads.pl
root 12887 0.0 0.0 11752 3504 pts/0 S 21:07 0:00 /usr/bin/perl /root/threads.pl
root 12888 0.0 0.0 11752 3504 pts/0 S 21:07 0:00 /usr/bin/perl /root/threads.pl
r
=============================================
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.