| Server IP : 217.160.0.143 / Your IP : 216.73.216.50 Web Server : Apache System : Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux User : u89353126 ( 3190106) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /usr/share/doc/libipc-shareable-perl/examples/ |
Upload File : |
#!/usr/bin/perl -w
#
# Test of shared hashes courtesy Joe Thomas <jthomas@women.com>
use strict;
use IPC::Shareable;
use vars qw($counter %hash);
tie %hash, 'IPC::Shareable', undef, {create => 'yes', destroy => 'yes'};
tie $counter, 'IPC::Shareable', undef, {create => 'yes', destroy => 'yes'};
$| = 1;
for (my $i = 0; $i < 3; $i++) {
sleep 1;
next if fork();
hashcount(3, 3);
exit;
}
while (1) {
last if wait() == -1;
}
sub hashcount {
my ($loops, $sleeptime) = @_;
for (my $i = 0; $i < $loops; $i++) {
(tied $counter)->shlock;
(tied %hash)->shlock;
$hash{++$counter} = $$;
print "Process $$ sees:\n";
for my $key (sort keys %hash) {
print "\$hash{$key} = $hash{$key}\n";
}
(tied %hash)->shunlock;
(tied $counter)->shunlock;
sleep $sleeptime;
}
}
exit;
__END__