Experimental Physics and
| |||||||||||||||||
|
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, -- Christopher A. Larrieu Computer Scientist, Acc. Controls Group Thomas Jefferson National Accelerator Facility
| ||||||||||||||||
ANJ, 10 Aug 2010 |
·
Home
·
News
·
About
·
Base
·
Modules
·
Extensions
·
Distributions
·
Download
·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing · |