Hash of Hashes Shared Across Parallel Forks Orphans Memory

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?

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;

}
LVL 2
ventolinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ventolinAuthor Commented:
See the man pages for 'ipcs' and 'ipcrm' for more info.
icrfCommented:
Did you ever get this one figured out? I found it and started playing today and didn't make much headway.

If I manually "tie %{$hash{'test'}}" before forking, it doesn't leak, but according to the docs, it's supposed to automagically tie references. If I let it automagically create it and then I manually destroy it "(tied %{$hash{test}})->remove" when it's all over, it doesn't leak. It sounds like the destory option isn't recursing through the tree as it should, but even calling clean_up or clean_up_all doesn't help, and they're supposed to destroy everything the current process created or encoutered.

Unless I'm implementing wrong, there's some serious issues with that module cleaning up after itself. Granted, it's designed for interprocess communication and it leaves the variables available for future processes to use, but they should go when implicitly told.
jmcgOwnerCommented:
Nothing has happened on this question in more than 6 weeks. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by icrf [grade B] (advice but not a solution).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

ventolinAuthor Commented:
You guys can go ahead an clean this up, but it still hasn't been answered to my satisfaction.
jmcgOwnerCommented:
Ventolin,

You have the option of requesting the question be closed (I'd recommend as a PAQ) and your points refunded. Just post a 0-point question in Community Support and a moderator will take a look.

I agree that you haven't been given a fully satisfactory answer, but after looking at the documentation myself and reading about icrm's experiments, I judged that he had done some work worth rewarding. I generally recommend a B grade on "answers" that are only steps along the road to an apparent solution. You, as the asker, can certainly disagree and the moderators are likely to give your desires more weight than my recommendation.

You might also like to try asking again, perhaps with more details. There has been a recent influx of new experts who might be interested in your problem.
PashaModCommented:
PAQed, with points refunded (500)

PashaMod
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.