Perl如何实现多线程并发编程?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1469个文字,预计阅读时间需要6分钟。
记录一些常用的模块和方法。多线程使用模块 `threads`,版本 5.010;使用 `threads`。
www.cnblogs.com/yeungchie/
记录一些常用的 模块 / 方法 。
多线程 使用模块threads
use 5.010;
use threads;
# 定义一个需要并发的子函数
sub func {
my $id = shift;
sleep 1;
print "This is thread - $id\n";
}
创建线程
new
sub start {
my $id = shift;
my $t = new threads \&func, $id;
return $t;
}
create
sub start {
my $id = shift;
my $t = create threads \&func, $id;
return $t;
}
async
可以不通过子函数来编写需要并发的过程,类似一个 "lambda" 。
本文共计1469个文字,预计阅读时间需要6分钟。
记录一些常用的模块和方法。多线程使用模块 `threads`,版本 5.010;使用 `threads`。
www.cnblogs.com/yeungchie/
记录一些常用的 模块 / 方法 。
多线程 使用模块threads
use 5.010;
use threads;
# 定义一个需要并发的子函数
sub func {
my $id = shift;
sleep 1;
print "This is thread - $id\n";
}
创建线程
new
sub start {
my $id = shift;
my $t = new threads \&func, $id;
return $t;
}
create
sub start {
my $id = shift;
my $t = create threads \&func, $id;
return $t;
}
async
可以不通过子函数来编写需要并发的过程,类似一个 "lambda" 。

