EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  <20022003  2004  2005  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  <20022003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Making CA calls from multi-threaded programs???
From: Christopher Larrieu <[email protected]>
To: Leonard Reder <[email protected]>
Cc: [email protected]
Date: Mon, 23 Sep 2002 08:14:29 -0400
Leonard,

 To use CA from EPICS 3.13 or earlier in a multi-threaded app,
you need to take several precautions:

   (1) The unix-side CA client library is not thread safe.  This
   means that you need to synchronize access to the library code
   between your threads.  Furthermore, you need to ensure that
   CA is in a safe state before synchronizing (e.g. you shouldn't
   interrupt a ca_pend_io() routine and assume that you can
   make a ca_search_and_connect() call).

   (2) If you're going to make CA calls from any other than the
   main thread, you'll need to re-build libCA and libCom with
   the appropriate compiler and linker directives to generate
   a well-formed multi-threaded application.  In developing the
   CZAR archiver here at Jefferson Lab, I created a new HOST_ARCH
   named HOST_ARCH_mt for each architecture against which
   I build the multi-threaded archiver (HP-UX 11, SunOS 5.8, Linux).

   (3) The technique I adopted for synchronizing access to CA
   between threads is to have one CA worker thread that repeatedly
   calls ca_pend_event() with a timeout of about 2 seconds.  After
   each such call, it determines if another thread wants access.  If
   so, it releases its mutex and then waits until it can reacquire it
   before repeating.  This technique works fine for the archiver
   because generally the time required to switch privilege between
   the threads needn't be any faster than several seconds.  If you
   need to switch privilege between threads faster, you might need
   to adopt a different technique.

 While I gather that the 3.14 CA code is thread safe, I don't yet
have any experience with it.  If it's ready, you might be better off
simply upgrading.  Jeff?

Hope this helps,

Chris


Leonard Reder wrote:


Hello,

I am developing sequencing code using a case tool called
Rhapsody.  This is part of the Keck Interferometer control
system and talks to EPICS PVs via a Keck Keyword API layer on
top of Channel Access.  I assume the Keyword API is built
on the portable CA libraries.  Currently running EPICS
3.13.0 Beta 12 at Keck and I assume the Keyword library
is linked to this.  Well up until now my Keywords (PVs) where used
in two threads and seemed to work just fine.  But I had
to add a keyword to a third thread and the following error
message is given:

CAC: unexpected select fail: 9=Bad file number
Segmentation fault

And my program segment faulted as shown.  Found this
message in $EPICS/base/src/ca/bsd_depen.c.  It is not
that the code does not run but rather this happens after
the code is running for a few minutes.  Any ideas about
exactly what is going on here?  Could an upgrade of EPICS
help this situation?

Thanks,

Len







--
Christopher A. Larrieu
Computer Scientist, Acc. Controls Group
Thomas Jefferson National Accelerator Facility



References:
Making CA calls from multi-threaded programs??? Leonard Reder

Navigate by Date:
Prev: Making CA calls from multi-threaded programs??? Leonard Reder
Next: Any Gigatronics users out there? Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  <20022003  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: Making CA calls from multi-threaded programs??? Leonard Reder
Next: Any Gigatronics users out there? Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  <20022003  2004  2005  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 ·