Subject: |
Re: Permissible in C to call CA I/O functions from callback? |
From: |
"J. Lewis Muir" <[email protected]> |
To: |
[email protected] |
Date: |
Fri, 07 Nov 2014 11:19:06 -0600 |
On 11/7/14 10:10 AM, Andrew Johnson wrote:
> The CA library uses multiple threads internally (each TCP socket that
> it opens to a server gets its own pair of threads for example), and
> enabling preemptive callbacks tells the library that the application
> is prepared for its callbacks to be run from any of the CA library
> threads as soon as they are ready to do so. That means you need
> to think carefully about the data that the callback routines are
> accessing, and add mutexes to protect against any race conditions that
> might otherwise occur.
Hi, Andrew.
Thanks for the clarification. One thing that's still unclear to me
is the semantics of callback execution in preemptive mode. In the CA
reference manual section "Thread Safety and Preemptive Callback to User
Code" it says,
"When the CA client library invokes a user's callback function, it
will always wait for the current callback to complete prior to
executing another callback function."
What exactly does this mean in preemptive mode?
For example, say I have a CA client running in preemptive mode, and it
has registered a state change subscription on two channels using the
same callback function, on_state_change, like this:
status = ca_create_subscription(DBR_LONG, 1, ctx->ch_nx,
DBE_VALUE, on_state_change, ctx, NULL);
status = ca_create_subscription(DBR_LONG, 1, ctx->ch_ny,
DBE_VALUE, on_state_change, ctx, NULL);
Now say the values of the ch_nx and ch_ny channels change at the same
time, and the CA server transmits this state change over the network.
In preemptive mode, can two CA threads be executing in on_state_change
concurrently? Or does the CA client library serialize the callback
calling such that, regardless of how many threads the CA client library
may have internally, it will still only call the on_state_change
callback function serially (e.g. call it for the ch_nx change, wait for
it to complete, then call it for the ch_ny change)?
As another example, say the value of ch_nx changes a few times in
quick succession and the CA server transmits these state changes over
the network. In preemptive mode, can two CA threads be executing in
on_state_change concurrently?
As yet another example, say I had specified a connection state
change callback, on_connection_state_change, when creating the
ch_nx and ch_ny channels. Can two CA threads be executing in
on_connection_state_change concurrently? Can two CA threads be
executing in on_connection_state_change and on_state_change (the
callback for the value change subscription) concurrently?
I'm sorry to ask all these questions, but the behavior isn't clear to
me based on reading the CA reference manual. (I'd be willing to try to
improve the manual if that would be a help.)
Thank you!
Lewis
- Replies:
- Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson
- References:
- Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson
- Re: Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson
- Navigate by Date:
- Prev:
Re: Problems with Dynamic Array population Eric Norum
- Next:
Re: Problems with Dynamic Array population Brown, David L.
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
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:
Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson
- Next:
Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
<2014>
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|