Chinaunix首页 | 论坛 | 博客
  • 博客访问: 438825
  • 博文数量: 116
  • 博客积分: 2756
  • 博客等级: 少校
  • 技术积分: 1163
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-29 21:21
文章分类

全部博文(116)

文章存档

2018年(1)

2017年(1)

2016年(30)

2015年(41)

2014年(23)

2011年(7)

2010年(9)

2008年(4)

分类: IT职场

2015-01-09 16:21:34

#!/usr/bin/perl -w

use strict;
use threads;

sub say_hello
{
    my $index = 0;
    my $tmp   = 0;

    foreach $index (1 .. 100)
    {
        printf("Hello thread! @_.\n");

        $tmp = rand(10);

        sleep($tmp);
    }

    return $tmp;
}

my $th_01 = threads->create("say_hello", "param1");
my $th_02 = threads->create("say_hello", "param2");
my $th_03 = threads->create("say_hello", "param3");
my $th_04 = threads->create("say_hello", "param4");

my $th_result_01 = $th_01->join;
my $th_result_02 = $th_02->join;
my $th_result_03 = $th_03->join;
my $th_result_04 = $th_04->join;

阅读(784) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~