#! perl -slw use strict; package Another::Module; use threads; sub new{ my $class = shift; return bless {@_}, $class; } sub run { my $self = shift; print $self, '|', \&Another::Module::run; print threads->self()->tid, ' : ', join' ', %{ $self }; sleep 2; $self->{'a new element'} = 'added in the second thread'; sleep 2; print threads->self()->tid, ' : ', join' ', %{ $self }; } package main; use threads; my $p : shared = Another::Module->new( some=>1, initialisation=>'data' ); print $p, '|', \&Another::Module::run; print threads->self()->tid, ' : ', join' ', %{ $p }; my $t = threads->new( \&Another::Module::run, $p ); print threads->self()->tid, ' : ', join' ', %{ $p }; $p->{'a new element'} = 'added in the main thread'; # Dirty. For demo only print threads->self()->tid, ' : ', join' ', %{ $p }; sleep 10; # Give the second thread a chance to end. print threads->self()->tid, ' : ', join' ', %{ $p }; $t->join;