Re: XForms: Re: fl_do_forms() and signals

Stephen Huyssoon (huyssoons@advancia.com)
Thu, 18 Feb 1999 11:50:02 -0600

# To subscribers of the xforms list from Stephen Huyssoon <huyssoons@advancia.com> :

Mark Lee wrote:

> # To subscribers of the xforms list from Mark Lee <mlee@heartlab.rri.on.ca> :
>
> On Tue, 16 Feb 1999, Steve Lamont wrote:
>
> > # To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :
> >
> >
> > Check my article "Infinite loop in fl_signal_caught() under IRIX 6.x"
> > dated December 1, 1998, in the archives. I discuss a workaround for a
> > similar problem.
> >
> > spl
>
> I read your article and tryed it, but it still hangs on the handler and it
> does not return cleanly. The other problem is that in your workaround you
> wait until the child process is finished, in my program the child process
> is still running and raises a signal at intermediate points in the program
> so I can't check for a SIGCHLD. The question is should I drop the signal
> approach to update forms from a child process and use a socket instead, if
> so any example code out there doing this.

Mark, signal handlers are tricky little buggers, you cannot
correctly call non reentrant functions.

What you need whenever you have more than one thread of control
is synchronicity.

What I suggest you do is to not use a signal handler at all but
to reguarly check for messages from the child. Use a pipe or
a fifo or a socket (probably want a unix domain socket).

You will need to write your own message loop in the parent as
you cannot give away control. That is, your main program
can never block.

I promise you that this approach will work well.

Now, signals seems interesting, I shall think on this.
The subtle problems that arise from using signals is
that the signal can happen at any time, in effect introducing
another temporary thread of control. So, in addition to
refraining from calling non reentrant functions, how do you
access your data correctly?

Consider this. In your signal handler, just increment a counter.
Then, in the course of your message processing, check this
counter and, if so indicated, attempt to receive a message from
your child (or thread). Now, don't attempt to reset the
counter in the main process, as your reset procedure may be
stepped on by the signal handler! (Right?) Only increment
ANOTHER counter, thus using the difference between the two
as the indication that a message is ready for reception.

I just love this stuff!

Be well and fork many children!

PS: You must get a copy of "Advanced Programming in the
UNIX Environment" by Richard Stevens. He will keep you
straight and provide many examples, he even has a web
site from which you can download sample code.

--
  (Stephen Huyssoon)
>=========================================>
  (huyssoons@advancia.com)

_________________________________________________ To unsubscribe, send the message "unsubscribe" to xforms-request@bob.usuhs.mil or see http://bob.usuhs.mil/mailserv/xforms.html XForms Home Page: http://bragg.phys.uwm.edu/xforms List Archive: http://bob.usuhs.mil/mailserv/list-archives/