Hello Monks,

I am trying out IPC::Sharable and running into a bit of a misunderstanding on my part. I was wondering if anyone could point me in the right direction.

When I try to use references I leak semaphores all over the map....

#!/usr/bin/perl -w use strict; use IPC::Shareable; use Data::Dumper; my %stuff; my $shm = tie %stuff, 'IPC::Shareable', undef, { destroy => 1 }; $SIG{INT} = sub { die "$$ dying\n" }; $SIG{CHLD} = sub { wait() }; my @children; foreach (1..10) { my $pid = fork(); if ($pid == 0) { push(@{$stuff{$_}}, $$); # this leaks # $stuff{$_} = $$; # this doesn't exit 0; } else { push (@children,$pid); } } waitpid ($_,0) foreach (@children); print Dumper(%stuff); print "\n\nCLEAR YOUR SHARED MEMORY\n"; print "(ipcs -m ; ipcrm -m ; ipcs -s ; ipcrm -s)\n";
Apparently using this for refs is bad, but I really would love to make a hash of arrays for managing the result set of my actual code....

Can I get some assistance understanding what I seem to have missed? Perhaps a pointer or so in the right direction for this type of thing?


jcpunk

In reply to Leaking Semaphores and Shared Memory by jcpunk

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.