#!/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

In reply to using tie on two arrays on IPC::Shareable makes array1 and array2 both same even though array2 is not updated. by mr_p

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.