use threads; use threads::shared; our $SHARED_DATA : shared; our @threads = (); # threads our $FINISHED : shared = 0; # for simulation state main(); main ( process() ) init( for () { push @threads, threads->new (\&Foo::run()...); } ) process( init(); finish(); ) sub finish { # our (@threads); { lock $FINISHED; $FINISHED = 1; } $_->join for @threads; } ################### # my class ################### package Foo; use threads; use threads::shared; sub new {} sub run { dothings() {lock $FINISHED; return if $FINISHED;} } sub dothings { lock ($SHARED_DATA); # ... }