Perl's documentation說: 因爲Perl 5.8線程編程已經可以使用模型稱爲解釋線程提供了一個新的Perl解釋器爲每個線程Perl的線程系統是如何工作的?
使用ps -Lm <pid>
與下面的程序,我可以看到線程並行運行,即它們在不同的內核中同時運行。但即使有4個線程(3和主)ps aux
只顯示一個Perl進程。
- 這是否意味着有每個線程在整個Perl解釋器?
- 是否Perl的線程映射到系統線程?
- 如果2爲真,在一個進程中如何可能有多個Perl解釋器?
use threads;
$thr = threads->new(\&sub1);
$thr2 = threads->new(\&sub1);
$thr3 = threads->new(\&sub1);
sub sub1 {
$i = 0;
while(true){
$i = int(rand(10)) + $i;
}
}
$thr->join;
http://stackoverflow.com/questions/9973860/use-cases-for-ithreads-interpreter-threads-in-perl-and-rationale-for-using-or – user454322
我強烈建議閱讀[這]( http://www.perlmonks.org/index.pl?node_id=288022)在任何項目中使用「Perl線程」之前。 – PSIAlt
此外,在perl 5.20發行說明中:現在勸阻基於解釋程序的線程 「interpreter- Perl提供的「基於線程的線程」並不是快速,輕量級的多任務處理系統,人們可能會期望或期望。線程的實現方式很容易被濫用。很少有人知道如何正確使用它們或者能夠提供幫助。 – Rob11311