#!/usr/local/bin/perl package My_mod; use warnings; use strict; use threads; use threads::shared; our $thread_abort : shared = 0; our $thread_continue : shared = 0; sub new { my ( $pkg,$config ) = @_; for ( 0..4 ) { threads->new( \&test_t ); } bless { }, $pkg; } sub test_t { my $iter = 0; while ( 1 ) { threads->yield; last if $thread_abort; next unless $thread_continue; ++$iter; } print "My iter count : $iter\n"; } sub activate { my $pkg = shift; $thread_continue = 1; } sub abort { my $pkg = shift; $thread_abort = 1; for my $thr ( threads->list ) { if ( $thr->tid && !($thr == threads->self ) ) { $thr->join } } } package main; my %config = ( 'test' => '3' ); my $node = new My_mod( \%config ); $node->activate; sleep(10); $node->abort;