|laziness, impatience, and hubris|
Re^4: IPC::Shareable sometimes leaks memory segmentsby stevieb (Canon)
|on Jul 09, 2019 at 16:34 UTC||Need Help??|
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).
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 :)