http://qs1969.pair.com?node_id=326108

xiper has asked for the wisdom of the Perl Monks concerning the following question:

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;