No such thing as a small change | |
PerlMonks |
IPC:Shareable: Sharing an object between parallel processesby Bloehdian (Beadle) |
on Oct 27, 2016 at 15:31 UTC ( [id://1174841]=perlquestion: print w/replies, xml ) | Need Help?? |
Bloehdian has asked for the wisdom of the Perl Monks concerning the following question: Hello Monks, this is the second time I encounter problems with IPC::Shareable and I have no clue, what the reason might be: I do not present the complete code overhere (it's just too big), but only the relevant parts. I have a prog which runs four parallel processes, a parent (parallel process (PP) #1) launching two childs, on of them being a tcp-listener (#2), the other one (#3) forks a process (#4) which runs a BGP Process (see Net::BGP::Process) which registers BGP peers (the latter fork() being necessary since the BGP Process will finally remain in an event loop and the loop in PP #3 must not be blocked). PP #2 should have access to one of the Peers (an object in Perl lingo) in PP #4. Therefore I tried to use IPC::Shareable to share this object amongst both PPs. Here are the code fragments relevant: PP #2:
PP #4:
When I run this I get the error message (as far as I could analyze this it is thrown when trying to assign $peer to $peer_ref): at /usr/lib/x86_64-linux-gnu/perl/5.22/Storable.pm line 341, at /usr/local/share/perl/5.22.1/IPC/Shareable.pm line 524.The documentation says that it should be possible to share objects via shared memory by assigning the object (or better: a non-tied referénce) to a tied variable. Lincoln Stein in his book mentions that it should be possible to store a reference object in a tied/shared hash, so I tried this (only showing code for PP #4 which is currently the trouble maker, made appropriate changes to PP 2):
On running this variant, I get the same mess, i.e. the same error message (Can't store CODE items) Any idea what the problem is here? Any suggestions how to share an object between the two processes? Cheers Bloehdian
Back to
Seekers of Perl Wisdom
|
|