#!/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(); } }