IPC::Shareable not sharing tied hashes 
Author Message
 IPC::Shareable not sharing tied hashes

I'm having trouble sharing hashes between forked processes using
IPC::Shareable.  Tied scalars are shared correctly, but tied hashes seem to
maintain separate states after being forked.  I see this behavior with
IPC::Shareable 0.51 and Perl 5.005_03 on both Red Hat Linux 6.1 and Solaris
7.

Anyone have any ideas on this?

Thanks,
Joe Thomas

Here's my test script:

#!/usr/bin/perl -w
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;

Quote:
}

while (1) {
 last if wait() == -1;

Quote:
}

sub hashcount {

 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;
 }

Quote:
}

exit;

The results I get:


Process 3737 sees:
$hash{1} = 3737
Process 3738 sees:
$hash{2} = 3738
Process 3739 sees:
$hash{3} = 3739
Process 3737 sees:
$hash{1} = 3737
$hash{4} = 3737
Process 3738 sees:
$hash{2} = 3738
$hash{5} = 3738
Process 3739 sees:
$hash{3} = 3739
$hash{6} = 3739
Process 3737 sees:
$hash{1} = 3737
$hash{4} = 3737
$hash{7} = 3737
Process 3738 sees:
$hash{2} = 3738
$hash{5} = 3738
$hash{8} = 3738
Process 3739 sees:
$hash{3} = 3739
$hash{6} = 3739
$hash{9} = 3739



Tue, 18 Feb 2003 06:21:58 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. IPC::Shareable not sharing tied hashes

2. using IPC::Shareable and using Tie::IxHash for the same hash

3. IPC:Shareable vs mod_perl ipcs not dying

4. IPC::Shareable not freeing memory

5. Tie & Shared Memory (creating shared perl vars)

6. bizarre(?) problem, tied hash of tied hashes

7. help with IPC::Shareable

8. IPC::Shareable problems

9. IPC::Shareable performance with forked processes.

10. IPC::Shareable on FreeBSD

11. IPC::Shareable quirks

12. IPC::Shareable and SOAP::Lite - strange bedfellows?

 

 
Powered by phpBB® Forum Software