首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Perl threads 撮要

2012-12-31 
Perl threads 摘要最近又写了一个多线程的小工具,对一些多线程的使用有了进一步的心得。Perl 创建线程有两

Perl threads 摘要

最近又写了一个多线程的小工具,对一些多线程的使用有了进一步的心得。

Perl 创建线程有两种方式,正常通过threads->create 创建线程,用async  创建一个调用匿名过程的线程,具体参考perldoc threads。线程共享变量需要使用 threads::shared,共享变量只能存储scalar,共享变量的引用,如果存储List Hash的引用需使用shared_clone([@list]) shared_clone({%hash})。线程创建后最好join 或者detach,否则在退出时会有warning。线程的join 方式,使用threads 中提供的函数接口,可以做到及时释放资源,参考下边的例子
4 run to the end.1 join? false2 join? false3 join? false3 run to the end.1 join? false2 join? false2 run to the end.1 join? false1 run to the end.

仅供参考,欢迎指正。

热点排行