I'm looking for a way to share data, in a non-blocking, asynchronous type of way, between parent & child (& further-child) on win32. The data is a complex data structure, so i'd rather avoid manually serialising it and pumping it through a pipe or socket. I'd also like to avoid
tieing &
untieing to a file over and over, for obvious reasons... A tied shared variable, something like
IPC::Shareable, would be nice, but it requires System V IPC type os calls. I've tried
Tie::Win32MemMap (recommended by
Mastering Perl/Tk, but nowhere to be found on CPAN), but it appears to be quiet buggy during my tests. Win32::Semaphore has been suggested, although it only shares a single number... any other suggestions?
Update: Some background, for those wanting to solve the 'bigger picture':
I have a Tk front-end that needs make calls to a linux back-end server over tcp, for which i am using SOAP. No problems there. However, SOAP blocks while making a call, which of course will stall the Tk event-loop. So the front-end forks (before any Tk stuff) a 'handler', whose job it is to do any time-consuming background processing, such as SOAP calls, while the event-loop cycles.
My plan was, and i already have the test code to do this, to have the Tk process pipe a command to the 'handler' and waitVariable( \%share{wait} ) on a shared hash, with args in $share{in}. The 'handler' does SOAPy-type stuff (in another sub-process so it can be canceled/killed/timed-out, if needed), writes the return data to $share{out} when finished, and $share{wait}++'s to continue the Tk code.
This method has the following advantages:
Doesn't stall the Tk event-loop
Can pass complex data structures both directions easily
Allows timeouts
Allows the user to click Cancel to abort processing
Easily portable
The Tk code only has to say %data = dispatch( 'get_data', $user ); or dispatch( 'cancel' ); and everything else is transparent
Unfortunately, i was relying on Tie::Win32MemMap to achieve the win32 side of this (this app will also run locally on the linux box). On testing, the underlying module Win32::MemMap (whose author seems to have gone AWOL), appears to be built for WinNT, and fails spectacularly in an alarming variety of ways under XP...
Code is available if required, in case my description wasn't that clear.
- ><iper
use japh; print;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.