Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: IPC::Shareable sometimes leaks memory segments

by stevieb (Canon)
on Jul 09, 2019 at 16:34 UTC ( #11102608=note: print w/replies, xml ) Need Help??


in reply to Re^3: IPC::Shareable sometimes leaks memory segments
in thread IPC::Shareable sometimes leaks memory segments

Problem 2 (problem that spawned this whole venture):

...if the initiating process goes out of scope/exits before a second process exits (ie. not forked, but a separate script in a different window), the entire shared memory goes away with the originating stack, leaving the remaining running separate process with no access to the shared data (crash).

Fix:

This is exceptionally tentative, and is currently just a test to ensure my thinking works. Add new example method leave_one() to IPC::Shareable, that acts exactly as clean_up(), but stops removing the underlying memory segments as soon as a single one is left. I also hacked the END block to do the same (END does the same thing as clean_up()).

For my test, I created a 2main.pl, which I introduce a sleep before calling B::run(). I start main.pl in a normal clean run, then immediately start 2main.pl. When main.pl's stack goes out of scope, 2main.pl resumes operation. Everything works, the data structure (and underlying memory segment) are still available.

Before, the clean up routines would remove ALL segments, destroying the data with it, which rendered 2main.pl to crash horribly.

At first I was trying to share the tied variable with other processes (as I thought a refcnt would work here), but that failed.

So now, I'll drum up something so that the variable in shared memory has at minimum the semaphore and memory segment IDs of whatever one is not cleaned up, and in my own software, write a routine that says "if there are no more of our objects in any proc whatsoever registered in the shared variable, blow away the last mem segment.

That's far more than hypothetical, but obviously the details will change as I move forward.

This'll likely be my last post on the topic now that I have the two core problems resolved, unless I find something else significantly interesting. Once I get the software re-written to be more adaptable and get my software working flawlessly, I'll do a big writeup :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11102608]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2019-11-13 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (74 votes). Check out past polls.

    Notices?