My script has hash of objects - All of a single class (SampleClass.pm). Following is the way that I used to create objects.
$objectHash{'foo'} = SampleClass->new();
$objectHash{'bar'} = SampleClass->new();
.
.
Then I spawn few threads (say 5) and each threads does its work as instructed to.
Now say Thread 1 writes to an object -
$objectHash{'foo'}->settimeWhenISaidHello($time);
and exits. Now when Thread2 takes up the work and checks for a value like below
$lastHelloTime = $objectHash{'foo'}->gettimeWhenISaidHello($time);
it gets undefined or empty value. I would like to share such values across threads. How is it possible?
Additionaly, my class constructor new
has hashes and array of hashes as member variables like below.
sub new
{
.
.
listOfGuysToSayHello = {}; #This is an array with guy name as key and array value as data
SchoolsWithStudentsToSayHellow = {}; #this is array of hashes
.
.
}
Further more I have already gone through this question - how to access perl objects in threads and the answer did not satisy my requirements.
Please let me know your thoughts.