mr_p has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w # sharetest - test shared variables across forks use lib "/home/samir/shmem/lib/lib"; use lib "/home/samir/shmem/lib/lib64"; use lib "/home/samir/shmem/lib/lib/perl5/site_perl/"; use IPC::Shareable; my @buffer; my @array1; my @array2; my $glue = 'data'; my %options = ( create => 'yes', exclusive => 0, mode => 0644, destroy => 'yes', ); $handle = tie @array1, 'IPC::Shareable', $glue, { destroy => 1 }; $handle2 = tie @array2, 'IPC::Shareable', $glue, { destroy => 1 }; $SIG{INT} = sub { die "$$ dying\n" }; for (1 .. 10) { unless ($child = fork) { # i'm the child die "cannot fork: $!" unless defined $child; squabble(); exit; } push @kids, $child; # in case we care about their pids } while (1) { print "array1: is @array1\n"; print "array2: is @array2\n"; sleep 1; } die "Not reached"; sub squabble { my $i = 0; while (1) { $handle->shlock(); $i++; @array1=(); push (@array1, "$i"); $handle->shunlock(); # $handle2->shlock(); # @array2=(); # push (@array2, "$i++"); # $handle2->shunlock(); } }
problem is array1 and array2 have same results eventhough array2 is not update.
...
I'm trying to use two arrays to one for the parent to update and the other for childerns to update.
been trying for a week now.
download
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using tie on two arrays on IPC::Shareable makes array1 and array2 both same even though array2 is not updated.
by ikegami (Patriarch) on Oct 06, 2009 at 17:47 UTC | |
by mr_p (Scribe) on Oct 06, 2009 at 18:04 UTC | |
by mr_p (Scribe) on Oct 06, 2009 at 18:10 UTC | |
by ikegami (Patriarch) on Oct 06, 2009 at 20:19 UTC |