#!/usr/bin/perl use strict; use warnings; use threads; use threads::shared; my $data:shared = ''; my $go_control:shared = 0; my $die_control:shared = 0; my $thr = threads->new(\&excecute); print "press a key to start thread\n"; <>; $go_control = 1; for( 1.. 10){ print "\t\t$data\n"; select(undef,undef,undef,.25); } print "press a key to stop thread\n"; <>; $go_control = 0; print "press a key to kill thread\n"; <>; $die_control = 1; print "press a key to exit\n"; <>; sub excecute{ my $count; while(1){ if($die_control){ print "thread finishing\n"; return} #wait for $go_control if($go_control){ if($die_control){ print "thread finishing\n"; return} $data = $count++; print $data,"\n"; select(undef,undef,undef,.25); }else{ select(undef,undef,undef,.25); }# sleep until awakened } return; }