EPICS Home

Experimental Physics and Industrial Control System


 
1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Synchronising CA shut down
From: <[email protected]>
To: <[email protected]>, <[email protected]>
Date: Fri, 16 Mar 2012 09:01:29 +0000
Thanks very much Jeff, sounds like it's doing exactly what I needed.  Ho hum, means my very rare blips (not exactly crashes, but looks like callback in bad context) on shutdown are something else...

On a related question: can you advise precisely when I need to call ca_flush_io()?  I've taken to scattering them through my code recently, and I think it's time to get rid of the surplus ones!  I'm currently call ca_flush_io() after:

1. ca_create_channel
2. ca_clear_subscription
3. ca_create_subscription
4. ca_array_get_callback
5. ca_array_put_callback
6. ca_array_put
7. ca_context_destroy

I'm guessing that (7) is completely bogus (and even possibly dangerous) and from what you've just said (2) is pointless.

________________________________________
From: Hill, Jeffrey O [[email protected]]
Sent: 15 March 2012 16:18
To: Abbott, Michael (DLSLtd,RAL,DIA); [email protected]
Subject: RE: Synchronising CA shut down

> For instance, if I have called:
>
>       ca_create_subscription( ... my_callback ..., &event_id)
>
> and then subsequently call ca_clear_subscription(event_id) is there any
> guarantee that I can rely on that my_callback() cannot be in progress when
> ca_clear_subscription() returns?

Internally, there is a callback lock and also a resource identifier for each subscription. The bottom line is that if you destroy the subscription the destroying thread will block until any callbacks in progress complete, purge the subscription from the resource table in the client, and send a message to the server canceling the subscription. If any subscription update messages are in flight they will be discarded because their resource id will be discovered to be no-longer installed in the client libraries resource table.

> A quick glance at the code (in ca) seems to show that although there is an
> epicsGuard taken during ca_clear_subscription, as far as I can tell the
> guard is dropped during callbacks ... for understandable reasons.

There are two global synchronization locks in the client library. A general mutual exclusion lock is held only briefly to enforce data structure consistency between threads. A callback control lock is held for much longer while a sequence of response messages are dispatched. It is used to enforce that only one callback at a time runs, to enforce non-preemptive callback mode, and to enforce that a callback isn't in progress at certain critical junctures.

Jeff

> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> On Behalf Of [email protected]
> Sent: Wednesday, March 14, 2012 7:08 AM
> To: [email protected]
> Subject: Synchronising CA shut down
>
> When running libca with asynchronous and preemptive callbacks, ie, I've
> called
>
>       ca_context_create(1)
>
> is there any guarantee about when subscription callbacks can occur?
>
> For instance, if I have called:
>
>       ca_create_subscription( ... my_callback ..., &event_id)
>
> and then subsequently call ca_clear_subscription(event_id) is there any
> guarantee that I can rely on that my_callback() cannot be in progress when
> ca_clear_subscription() returns?
>
> The problem is, of course, one of resource management -- at what point is
> it safe to delete the resources associated with the channel and needed by
> my_callback()?
>
>
> In an ideal world I would hope that ca_clear_subscription() would block
> until any outstanding callbacks (potentially running in other cores) had
> completed together with providing a guarantee that there would be no
> further callbacks ... but I'm guessing such hopes are unfounded?
>
> Of course, the same question applies to calling ca_clear_channel() when
> there are outstanding put or get callbacks that might complete at a
> peculiarly inconvenient moment.
>
> In the absence of such guarantees what can I do to reduce or eliminate
> potential race conditions when closing channels and subscriptions?  At the
> moment the only remedy I can think of is to wait a moment, not exactly the
> stuff of guarantees.
>
>
> A quick glance at the code (in ca) seems to show that although there is an
> epicsGuard taken during ca_clear_subscription, as far as I can tell the
> guard is dropped during callbacks ... for understandable reasons.
>
> --
> This e-mail and any attachments may contain confidential, copyright and or
> privileged material, and are for the use of the intended addressee only.
> If you are not the intended addressee or an authorised recipient of the
> addressee please notify us of receipt by returning the e-mail and do not
> use, copy, retain, distribute or disclose the information in or attached
> to the e-mail.
> Any opinions expressed within this e-mail are those of the individual and
> not necessarily of Diamond Light Source Ltd.
> Diamond Light Source Ltd. cannot guarantee that this e-mail or any
> attachments are free from viruses and we cannot accept liability for any
> damage which you may sustain as a result of software viruses which may be
> transmitted in or with the message.
> Diamond Light Source Limited (company no. 4375679). Registered in England
> and Wales with its registered office at Diamond House, Harwell Science and
> Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
>
>
>
>


-- 
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. 
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
 





Replies:
RE: Synchronising CA shut down Hill, Jeffrey O
References:
Synchronising CA shut down michael.abbott
RE: Synchronising CA shut down Hill, Jeffrey O

Navigate by Date:
Prev: RE: ENV Variables in EDM Szalata, Zenon M.
Next: Re: Invitation to test cothread.catools release candidate Matt Newville
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: Synchronising CA shut down Hill, Jeffrey O
Next: RE: Synchronising CA shut down Hill, Jeffrey O
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024