{ package IPConnection; use threads; use threads::shared; use Time::HiRes qw(time sleep); sub new { my $class = shift; my $arg = shift; share (my %this); $this{_socket} = shift; $this{_sendBufferCount} = 0; bless \%this, $class; return \%this; } sub handleConnection { my $this = shift; my $someData = "foo"; { # scope for lock on $this lock ($this); push @{$this->{_sendBuffer}}, $someData; # manipulate the send buffer $this->{_sendBufferCount}++; # manipulate the send buffer } # release lock } }