Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019 
<== Date ==> <== Thread ==>

Subject: Re: Calling ca_context_create(1) too late
From: Andrew Johnson <anj@aps.anl.gov>
To: tech-talk@aps.anl.gov
Date: Fri, 19 Apr 2013 10:45:52 -0500
Hi Michael,

On 2013-04-19 michael.abbott@diamond.ac.uk wrote:
> I've just discovered that calling ca_context_create(1) after iocInit()
> appears to succeed (it returns ECA_NORMAL) ... but the resulting context
> is not very healthy!  In my particular case I find that
> ca_array_get_callback delivers zero length data, but I expect other deeper
> problems are to be found.

Is your code running in the main thread, or its own private thread?  If this 
is a private thread then Mark's comment applies — you must ensure that the 
thread does not call any other CA functions before ca_context_create() is run.  
If this code is running in the IOC's main thread then that's a different 
issue; I'm not sure what context the main IOC thread belongs to, if any, but 
you probably can't assume that code running after iocInit is the first routine 
to create a CA context for the main thread.

> I understand that I need to call ca_context_create() a good deal earlier,
> but I don't really understand why it appears to succeed -- is it possible
> for an error code to be returned instead, please?  (In some future version
> of EPICS, I'm testing this on 3.14.11.)

It does return a status, but it is not a failure to have multiple contexts 
running in a process at the same time.  I'm guessing that the API can't 
distinguish your case from a more advanced user, so it's quite happy to do 
what you asked.

> Alternatively, is there some reliable way I can test whether it has
> succeeded?  I don't have full control over when my library is initialised,
> so detecting an error immediately would be more friendly to the user.

You can use ca_current_context() to find out if there is context set for the 
current thread yet.  This returns a NULL pointer if no context has been 
created yet.  If the result is not NULL you may be able to use the 
undocumented (and mis-spelled) routine (with a prototype in cadef.h)
    int ca_preemtive_callback_is_enabled(void);
to find out whether that context is preemptive or not.

HTH,

- Andrew
-- 
It is difficult to get a man to understand something, when his salary
depends upon his not understanding it. -- Upton Sinclair


Replies:
RE: Calling ca_context_create(1) too late michael.abbott
RE: Calling ca_context_create(1) too late michael.abbott
References:
Calling ca_context_create(1) too late michael.abbott

Navigate by Date:
Prev: RE: Calling ca_context_create(1) too late Mark Rivers
Next: Re: Add choice to dbd file Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019 
Navigate by Thread:
Prev: RE: Calling ca_context_create(1) too late michael.abbott
Next: RE: Calling ca_context_create(1) too late michael.abbott
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019 
ANJ, 20 Apr 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·