#!/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;
阅读(832) | 评论(0) | 转发(0) |