#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; $| = 1; my %threads; foreach (1..10){ share ($threads{$_}{'die'}); $threads{$_}{'die'} = 0; } foreach (1..10) { $threads{$_}{'thread'} = threads->new('StartTest'); } my @threads = (1..10); foreach(@threads){ $threads{$_}{'die'} = 1; $threads{$_}{'thread'}->join; } print "\n", "All threads done\nHit Enter to exit\n"; <>; ########################################################## sub StartTest { my $self = threads->self; print "Thread ", $self->tid, " started\n"; while(1){ if( $threads{$_}{'die'} == 1){goto FINISH} else{ select(undef,undef,undef, 5) }; } FINISH: print "Thread ", $self->tid, " ending\n"; }