EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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

Subject: RE: segmentation fault in ca_task_initialize running in Linux
From: "Jeff Hill" <[email protected]>
To: "'Margaret Votava'" <[email protected]>, <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>
Date: Fri, 17 Feb 2006 15:31:09 -0700
Hello Margaret,

This is mantis entry 239.

The issue you have discovered occurs only when calling ca_context_create
(a.k.a. ca_task_initialize) from your C++ file scope object's constructor.

The static variable "ca_client_context::defaultServiceInstallMutex" is also
file scope, and this implies that it's constructor along with the
constructor of your device_attr_stubs both run before main() is called.

Which file scope constructor runs first is very C++ compiler implementation
dependent.

Let me know if the attached patch resolves your troubles.

Jeff

cvs diff -u -wb -i -- ca_client_context.cpp oldAccess.h (in directory
D:\users\hill\R3.14.dll_hell_fix\epics\base\src\ca\)
Index: ca_client_context.cpp
===================================================================
RCS file:
/net/phoebus/epicsmgr/cvsroot/epics/base/src/ca/ca_client_context.cpp,v
retrieving revision 1.9.2.18
diff -c -u -w -b -i -r1.9.2.18 ca_client_context.cpp
cvs diff: conflicting specifications of output style
--- ca_client_context.cpp	13 Apr 2005 17:28:13 -0000	1.9.2.18
+++ ca_client_context.cpp	17 Feb 2006 22:22:11 -0000
@@ -47,6 +47,7 @@
 {
     epicsThreadPrivateDelete ( caClientCallbackThreadId );
     caClientCallbackThreadId = 0;
+    delete ca_client_context::pDefaultServiceInstallMutex;
 }
 
 // runs once only for each process
@@ -54,13 +55,14 @@
 {
     caClientCallbackThreadId = epicsThreadPrivateCreate ();
     assert ( caClientCallbackThreadId );
+    ca_client_context::pDefaultServiceInstallMutex = new epicsMutex;
     epicsAtExit ( cacExitHandler,0 );
 }
 
 extern epicsThreadPrivateId caClientContextId;
 
 cacService * ca_client_context::pDefaultService = 0;
-epicsMutex ca_client_context::defaultServiceInstallMutex;
+epicsMutex * ca_client_context::pDefaultServiceInstallMutex;
 
 ca_client_context::ca_client_context ( bool enablePreemptiveCallback ) :
     ca_exception_func ( 0 ), ca_exception_arg ( 0 ), 
@@ -77,9 +79,7 @@
 
     epicsThreadOnce ( & cacOnce, cacOnceFunc, 0 );
 
-    {
-        // this wont consistently work if called from file scope
constructor
-        epicsGuard < epicsMutex > guard (
ca_client_context::defaultServiceInstallMutex );
+    epicsGuard < epicsMutex > guard (
*ca_client_context::pDefaultServiceInstallMutex );
         if ( ca_client_context::pDefaultService ) {
             this->pServiceContext.reset (
                 & ca_client_context::pDefaultService->contextCreate ( 
@@ -88,7 +88,6 @@
         else {
             this->pServiceContext.reset ( new cac ( this->mutex,
this->cbMutex, *this ) );
         }
-    }
 
     this->sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
     if ( this->sock == INVALID_SOCKET ) {
@@ -734,8 +733,9 @@
 
 void ca_client_context::installDefaultService ( cacService & service )
 {
-    // this wont consistently work if called from file scope constructor
-    epicsGuard < epicsMutex > guard (
ca_client_context::defaultServiceInstallMutex );
+    epicsThreadOnce ( & cacOnce, cacOnceFunc, 0 );
+
+    epicsGuard < epicsMutex > guard (
*ca_client_context::pDefaultServiceInstallMutex );
     if ( ca_client_context::pDefaultService ) {
         throw std::logic_error
             ( "CA in-memory service already installed and can't be
replaced");
Index: oldAccess.h
===================================================================
RCS file: /net/phoebus/epicsmgr/cvsroot/epics/base/src/ca/oldAccess.h,v
retrieving revision 1.47.2.14
diff -c -u -w -b -i -r1.47.2.14 oldAccess.h
cvs diff: conflicting specifications of output style
--- oldAccess.h	19 Oct 2004 20:48:51 -0000	1.47.2.14
+++ oldAccess.h	17 Feb 2006 22:07:21 -0000
@@ -286,6 +286,9 @@
     void operator delete ( void * );
 };
 
+extern "C" void cacOnceFunc ( void * );
+extern "C" void cacExitHandler ( void *);
+
 struct ca_client_context : public cacContextNotify
 {
 public:
@@ -412,8 +415,10 @@
 	ca_client_context ( const ca_client_context & );
 	ca_client_context & operator = ( const ca_client_context & );
 
+	friend void cacOnceFunc ( void * );
+	friend void cacExitHandler ( void *);
     static cacService * pDefaultService;
-    static epicsMutex defaultServiceInstallMutex;
+    static epicsMutex * pDefaultServiceInstallMutex;
 };
 
 int fetchClientContext ( ca_client_context * * ppcac );

***** CVS exited normally with code 1 *****



References:
segmentation fault in ca_task_initialize running in Linux Margaret Votava

Navigate by Date:
Prev: CA Port numbers now official Kay-Uwe Kasemir
Next: genSub tutorial needed Dennis Nicklaus
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: segmentation fault in ca_task_initialize running in Linux Margaret Votava
Next: RE: segmentation fault in ca_task_initialize running in Linux Jeff Hill
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·