I think I'm understanding things correctly. I've started on my second
exercise and have working code. Here is the basics of the program
1. It does a ping heartbeat on various hosts
2. A piece of data is shared among threads.
3. There is a thread for each target.
4. There is one thread that will notify when a host goes down.
I have a few questions.
67 # Read out config file:
68 my $xml = XMLin "config.xml";
XMLIn returns a reference to a hash. How can I share that data?
Currently I'm creating data from that data.
33 my %data;
34 my $lock;
35 share($lock);
36 share(%data);
....
74 {
75 lock($lock);
76 foreach my $ref (keys %{$xml->{'host'}}) {
77
78 # We need to share this child of the hash and this
79 # Child's elements
80 $data{$ref} = &share({});
81
82 $data{$ref}{'ip'} = $xml->{'host'}{$ref}{'ip'};
83 $data{$ref}{'last_ping'} = $xml-
>{'host'}{$ref}{'last_ping'};
84 $data{$ref}{'counter'} = 0;
85 $data{$ref}{'up'} = 0;
86 $data{$ref}{'interval'} = $xml-
>{'host'}{$ref}{'interval'};
87
88 print "Creating thread to monitor: $data{$ref}{'ip'}\n";
89
90 # Fire off the thread.
91 threads->create(\&worker_bee, $ref);
92 }
93 }
For each level of a hash do I have to share it?
80 $data{$ref} = &share({});
Without that the programed died because of invalid value applied to
shared variable.
How deep can the hash go and still be shared? Do I need to do that for
each level if I expect many branches?
The program is at:
http://buford.linxdev.com/hb.pl
I think I've got some of this nailed thing. I appreciate the pointers.
Thanks,
Chris