I have a simplified example of a problem I'm trying to solve (below). Up until recently, I have had much success with the IPC::Shareable module for sharing variables across parallel forks.

Unfortunately, when I use a hash of hashes with IPC::Shareable, I get orphaned shared memory segments. If I remove the line that says $hash{'test'}{'test'} = 'test', then the script runs without orphaning memory... The maintainer of the module no longer lives at the listed email address, and if I could get a hash of hashes to share across parallel forks, it would reduce my run-times dramatically...

Any thoughts for another way short of Open2, udp datagrams, or any other such ugliness?

See the man pages for 'ipcs' and 'ipcrm' for more info.

Broken code below:
---

!/usr/bin/perl -w use lib 'site_perl'; use IPC::Shareable(':all'); use Parallel::ForkManager; my $forkman = new Parallel::ForkManager(1); my $key; my %hash; my %options = ( create => 'yes', mode => 0644, exclusive => 0, destroy => 'yes' ); my $index; my $HANDLE = tie %hash, 'IPC::Shareable', 'data', { %options }; for($index=1; $index <= 7; $index++) { print "Spawning process: $index\n"; $forkman->start and next; do_this($index); $forkman->finish; } $forkman->wait_all_children; print "All children are done\n"; foreach $key (sort keys %hash) { print "PID of process $key = $hash{$key}\n"; } sub do_this { my $index = $_[0]; $HANDLE->shlock(); $hash{$index} = "PID: $$"; $hash{'test'}{'test'} = 'test'; $HANDLE->shunlock(); return 0; }

In reply to Hash of Hashes Shared Across Parallel Forks Orphans Memory by Anonymous Monk

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.