jcpunk has asked for the wisdom of the Perl Monks concerning the following question:
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....
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....#!/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";
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Leaking Semaphores and Shared Memory
by gmargo (Hermit) on Nov 10, 2009 at 01:16 UTC |