Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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;

    In reply to Shared variables under win32? by xiper

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or or How to display code and escape characters are good places to start.
    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (5)
    As of 2022-08-13 11:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?