共 1,393 篇文章
共 6,621 篇文章及评论
博客分类
Blog Roll
- Association for Computing Machinery TechNews (ACM)
- Go Parallel! (Dr. Dobbs)
- HPCwire (Tabor Communications, Inc.)
- insideHPC (John West)
- Joe Duffy's Weblog (Microsoft)
- Microsoft Parallel Programming Development Center (Microsoft Germany)
- MultiCoreInfo.com
- scalability.org (Scalable Informatics)
- Software Dev Blog (Intel Germany)
- Soft Talk Blog (Intel United Kingdom)
- The Moth (Microsoft)
Archives
帖子来自 pengsixiang 
Perl 程序在做多线程时 async 使用一定要谨慎
作者: pengsixiang (1 篇文章) 日期: 二月 16, 2011 在 2:15 下午
评论 (0)
使用Perl开发Linux和Unix维护管理脚本是常用的手段,其中也会因为作业要求大量使用多线程技术。通常下我们使用threads::create()创建一个新的线程,这时候往往我们会创建一个$thr来保存线程ID,并在程序结束后由threads回收线程资源。但是threads还提供了一个叫做async的函数,这个函数提供程序块(BLOCK)的方式创建匿名线程。这个函数帮助我们解决多线程中的同步问题。例如我们在多线程中使用print方法时会发现,我们的print结果没有及时的回显到屏幕上,那么这个函数将帮我解决这个问题。 但是在使用async函数时一定要小心,那就是函数并不会在BLOCK块执行完成后释放匿名线程资源,这将会直接导致内存溢出的严重后果。 当async函数导致内存溢出后,无法再创建新的匿名线程时,会出现这样的错误警告: Thread creation failed: pthread_create returned 12 at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/threads.pm line 117. 并且我们使用ps ...
