EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Program calling CA from witrin a posix signal handler
From: "Jeff Hill" <[email protected]>
To: "'Eric Norum'" <[email protected]>, "'Robert Soliday'" <[email protected]>
Cc: "'tech-talk'" <[email protected]>
Date: Fri, 30 Jul 2004 17:23:04 -0600
Just to confirm previous conclusions on this matter. I would not recommend
calling any of the CA functions from within a POSIX signal handler. 

Among other reasons, the execution context for signals can vary depending on
the type of signal and the implementation of the OS. On some systems the
process global signals are run within the context of a special thread. In
other situations the signal handlers are more like interrupts. The CA
libraries are thread safe, but not interrupt safe. Thread safety requires
protection by mutual exclusion semaphores. Interrupt safety requires a much
lower level, and more intrusive protection mechanism (which the CA libraries
do not use).

The idea of setting a shutdown flag from within the signal handler sounds
like a much better (more portable and reliable) approach.

Jeff


> -----Original Message-----
> From: Eric Norum [mailto:[email protected]]
> Sent: Monday, July 26, 2004 1:30 PM
> To: Robert Soliday
> Cc: tech-talk
> Subject: Re: Proglem doing CA calls after catching a signal
> 
> Robert Soliday wrote:
> 
>  > int sigint=0;
> ..
> ..
> ..
> > /* wrapper for ca_pend_event that allows breaking out early if the
> >    flag is set from a signal handler. Unlike ca_pend_event, a timeout
> >    of zero will not be converted to infinity. */
> > long oag_ca_pend_event(double timeout, int *flag) {
> >   long status=ECA_NORMAL;
> >
> >   if (timeout <= 0)
> >     ca_poll();
> >   while (timeout > 0) {
> >     if (*flag)
> >       return(status);
> >     if (timeout > 1) {
> >       status = ca_pend_event(1);
> >       timeout -= 1;
> >     } else {
> >       status = ca_pend_event(timeout);
> >       timeout = 0;
> >     }
> >   }
> >
> >   return(status);
> > }
> 
> I'm not completely up to speed on the latest 'alias/noalias' state of C
> pointers, but I think that it would be safer to add some 'volatile'
> keywords
> to protect yourself from overzealous optimizers:
> 
> volatile int sigint = 0;
> ..
> ..
> long oag_ca_pend_event(double timeout, volatile int *flag) {
> ..
> ..
> 
> --
> Eric Norum                                 [email protected]
> Advanced Photon Source                     Phone: (630) 252-4793
> Argonne National Laboratory



References:
Re: Proglem doing CA calls after catching a signal Eric Norum

Navigate by Date:
Prev: RE: problem with the monitor-function (c++) Jeff Hill
Next: How to pass constant string into a genSub or sub record Susanna Jacobson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Proglem doing CA calls after catching a signal Eric Norum
Next: Re: Proglem doing CA calls after catching a signal Robert Soliday
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Aug 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·