package Counter; use strict; use threads; use threads::shared; my $counter : shared = 0; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; lock $counter; $counter = shift; bless($self,$class); return $self; } sub incCounter { lock $counter; $counter++; } sub getCounter { return $counter; } 1;