EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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

Subject: RE: Request for help re ca_add_event call under MATLAB
From: "Jeff Hill" <[email protected]>
To: <[email protected]>, "'Rowland, J \(James\) '" <[email protected]>, "'Carl Lionberger'" <[email protected]>, "'Terebilo, Andrei'" <[email protected]>, "'Ernest L. Williams Jr.'" <[email protected]>, <[email protected]>
Cc: <[email protected]>, <[email protected]>
Date: Mon, 2 Feb 2004 23:56:54 -0700
Steve,

Have you set up a ca client context with preemptive callbacks disable? If
so, then ca client library callbacks are not allowed to run unless your main
thread is in the ca library. This will protect thread unsafe libraries.

Where we have seen trouble before was when certain 3rd party thread aware
libraries were integrated with EPICS R3.14. For example, with JAVA it is
necessary for a new auxillary thread (a thread not created by JAVA) to
register with the JAVA runtime libraries prior to calling the JAVA runtime
for the first time.

I would consult the MATLAB manual concerning multi-threading to see if
similar requirements are in place. If so, then send me an e-mail and I will
send some suggested solutions which worked with JCA (involving thread
private variables).

Of course, there is also the possiblity that you have set up a ca client
context with preemptive callbacks enabled and MATLAB isnt thread safe at
all. In that case you will only need to change the mode to non-preemptive
callback to resolve your troubles.

Jeff

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] 
> Sent: Monday, February 02, 2004 6:06 PM
> To: Jeff Hill; Rowland, J (James) ; Carl Lionberger; 
> Terebilo, Andrei; Ernest L. Williams Jr.; 
> [email protected]
> Cc: [email protected]
> Subject: Re: Request for help re ca_add_event call under MATLAB
> 
> 
> 
> 
> 
> 
> Ok, I believe I've found out why my program is hanging, but 
> it has just
> raised more questions in my mind about what is going on inside Channel
> Access and MATLAB.
> 
> It appears that the mexPrintf statements inside the 
> EventHandler are the
> cause of the problem.  When these are removed and replaced by another
> statement such as:
> 
> mexEvalString("beep");
> 
> everything works fine.
> 
> The general problem seems to be that there is a severe 
> limitation on what
> MATLAB functions can be used inside the Channel Access 
> callback functions.
> For instance, anything that writes to the MATLAB command 
> window will cause
> a hang or a crash.  In addition, other commands which do not 
> directly write
> to the command window, such as mexEvalString("figure"), will 
> also cause
> MATLAB to crash.
> 
> It is interesting to note that I can use any MATLAB command I 
> like in the
> main mexFunction() routine and it works fine.  This isn't surprising
> because that's what mex files are used for.
> 
> It appears to me that some information about the local MATLAB 
> context is
> being lost in the Channel Access calback routines.  Either 
> that or there is
> some sort of timing issue related to the use of Channel 
> Access callbacks.
> I've has a look through the MATLAB help to see if there is 
> any information
> but can't find anything.
> 
> I would be interested to know if anyone has any insights into 
> this, because
> a solution would mean that the mcamon functionality would 
> become far more
> stable and useful than it is at the moment.
> 
> Steve Banks
> Australian Synchrotron Project
> Department of Infrastructure
> Level 18, 80 Collins Street
> Melbourne   VIC   3000
> tel:  +613 9655 6303
> fax:  +613 9655 8666
> web: www.synchrotron.vic.gov.au
> ----- Forwarded by Steven Banks/CORE/DOI on 03/02/04 10:57 AM -----
>                                                               
>                                                               
>            
>                       Steven Banks                            
>                                                               
>            
>                                                To:       
> "Jeff Hill" <[email protected]>, "Rowland, J (James) "          
>                 
>                       02/02/04 01:13 PM         
> <[email protected]>, Carl Lionberger 
> <[email protected]>, "Terebilo,     
>                                                 Andrei" 
> <[email protected]>, "Ernest L. Williams Jr." 
> <[email protected]>      
>                                                cc:       
> Richard Farnsworth/CORE/DOI@DOI                               
>                 
>                                                Subject:  
> Request for help re ca_add_event call under MATLAB            
>                 
>                                                               
>                                                               
>            
> 
> 
> 
> Hi Guys,
> 
> I'm hoping that one of you can give me some advice or assistance on a
> problem that I am encountering in my work in enhancing the 
> (MATLAB Channel
> Access) MCA functionality.  I have essentially tried 
> everything I can think
> of to diagnose the problem and have now run out of ideas.
> 
> I have reduced the problem to a small piece of code which I 
> have attached.
> 
> The problem is occurring following the call to the Channel 
> Access routine
> ca_add_event().  If the timeout value in the ca_pend_event() 
> call is set to
> 1e-12 seconds (as per the original MCA code) my little MATLAB 
> program hangs
> immediately and the callback function EventHandler() does not 
> get called.
> If I set the timeout value in the ca_pend_event() call to 1 second,
> EventHandler() gets called immediately, however the program 
> hangs as soon
> as the value of the PV changes.
> 
> I have tried running the original MCA code and it works fine. 
>  I can see no
> fundamental difference between the use of ca_add_event() and
> ca_pend_event() in my program and the original MCA code, 
> however there must
> be something subtle (or maybe not so subtle) that I am missing.
> 
> Also, I do not understand why the ca_pend_event() call never returns
> ECA_NORMAL.  It always returns ECA_TIMEOUT, but this also 
> happens with the
> original MCA code.
> 
> To run my code, just cd in MATLAB to the directory where you 
> have placed
> the attached files, type "mcacompile" to compile the mca.dll 
> and then type
> "mca(1)" to run it.
> 
> (See attached file: mextest.zip)
> 
> Thanks in anticipation,
> 
> Steve Banks
> Australian Synchrotron Project
> Department of Infrastructure
> Level 18, 80 Collins Street
> Melbourne   VIC   3000
> tel:  +613 9655 6303
> fax:  +613 9655 8666
> web: www.synchrotron.vic.gov.au
> 



Navigate by Date:
Prev: RE: buying tornado seats for EPICS application developers Hunt Steven
Next: registerRecordDeviceDriver Problem Kim, Kukhee
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: buying tornado seats for EPICS application developers Hunt Steven
Next: registerRecordDeviceDriver Problem Kim, Kukhee
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  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 ·