[Chicago-talk] Using Storable to exchange data between 2 processes
Jay Strauss
me at heyjay.com
Fri Jan 23 21:05:42 CST 2004
this seems to work fine, and its much more speedy than the real life
process. And, it prevents a race condition
Jay
#!/usr/bin/perl
use strict;
use Storable qw( freeze thaw );
use IPC::ShareLite;
my $share = new IPC::ShareLite( -key => 1971,
-create => 'yes',
-destroy => 'no' ) or die $!;
if (my $pid = fork) {
parent();
}
else {
child();
}
sub parent {
my $data;
while (1) {
sleep 1;
$data = thaw( $share->fetch );
print $data->{IBM}{last},"\n";
}
}
sub child {
my $data = {};
foreach (0..10000000) {
$data->{IBM}{last} = $_;
$share->store( freeze($data) );
}
}
More information about the Chicago-talk
mailing list