package main; $main::VERSION = (q$Revision: 1.7 $ =~ /(\d+)/g)[0]; use strict; use warnings; use threads; # these just call &sub1 with the arguments being the thread's # name and the amount of time to sleep prior to printing out the # thread's name and information again my $thr1 = threads->create(\&sub1, q(odin), 3); my $thr2 = threads->create(\&sub1, q(dva), 5); my $thr3 = threads->create(\&sub1, q(tri), 7); my $thr4 = threads->create(\&sub1, q(chetyre), 9); my $thr5 = threads->create(\&sub1, q(pyat), 11); $thr1->join(); $thr2->join(); $thr3->join(); $thr4->join(); $thr5->join(); sub sub1 { my $thread_name = shift; my $sleep_time = shift; my $total_time = 100; my $run_time = 0; while ( $run_time < $total_time ) { sleep $sleep_time; my $thread = threads->self(); # threads->tid() is the thread ID #, $$ is the Perl PID print qq(Unga! $thread_name/$$-) . $thread->tid() . qq(, slept for $sleep_time, $run_time\n); $run_time += $sleep_time; } }