I'm getting a problem using using fork() with Win32::GUI and wondered if
anyone else had had any success.

I can get a program to create a pipe for communication, and fork.  I then
have the parent handle the window actions and the child do any actual work
required.  When a windows event happens the parent tells the child what to
do, the child does perfoms the required action and updates the window with
the required results.  The advantage of this method is that you can
minimise or move the window while actions are being performed.

This all works fine (and, as an aside, compiles fine with Perl2Exe) so I
decided to try a further enhancement.  One of my programs uses a module
that can give debugging info to STDOUT.  It seemed a nice idea to capture
this and display it on my window.  To do this I needed a parent to handle
the window, a child to handle screen updating and a further child (or
grandchild) to carry out the required actions.  The pipes required are from
parent to child, and child to grandchild in both directions (ie parent
tells child action to be performed, child tells grandchild, captures
grandchilds STDOUT and displays it in the required control). As psuedo code
this looks something like this

      Use Win32::GUI
      ....
      my $Win= ....
      # create windows with appropriate controls
      # create pipe for parent/child communication

      if ( fork() ) {
      # Parent with GUI event subs
      # start GUI event loop

      } else {
      # Child
      # create pipes for Child/Grandchild communication
         if ( fork() ) {
            #Child
            # loop {
            #   read command from parent
            #   report them to grandchild
            #   diplay grandchilds output in appropriate control
            # }
         } else {
            #Grand Child
            # loop {
            #   Read command from child
            #   perform required action
            #}
         }
      }

This again works fine, except if a large (I haven't tried to work out the
limit) amount of data is sent from the grandchild and displayed in what
ever contol.  When this happens the program crashes on exit.  The
grandchild and child exit correctly, memory usage shoots and then I get a
Dr Watson error.

My guess is that its something to do with memory allocation for the
control. I've tried using a RichEdit, a TextBox and even displaying the
piped data in the status bar, all with the same results.

Any suggestions?

Thanks,

Kev.






Reply via email to