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
<2004>
2005
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
<2004>
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|