[asterisk-dev] Scheduler and event callbacks - what thread?

Ian Pilcher arequipeno at gmail.com
Tue Nov 1 17:48:12 CDT 2011


I'm back with another thread-related question.

chan_sip uses at least two types of callbacks -- an event callback
registered with ast_event_subscribe() and a scheduler callback
registered with ast_sched_add().  The two callback functions are using
a shared static variable to communicate state.

Pseudo-code:

  static int event_sched_id = -1;

  static void event_callback(...)
  {
      if (event_sched_id == -1) {
          event_sched_id = ast_sched_add(..., sched_callback, ...);
  }

  static int sched_callback(...)
  {
      event_sched_id == -1;
      ...
  }

Is there anything ensures that these two callbacks will always be called
from the same thread?  If not, then the shared variable needs a mutex.

Even if they are always executed in the same thread, am I correct in
thinking that there's a possibility of the thread being interrupted by
an event or scheduled action -- in which case the shared variable needs
to be volatile and atomic?

Thanks!

-- 
========================================================================
Ian Pilcher                                         arequipeno at gmail.com
"If you're going to shift my paradigm ... at least buy me dinner first."
========================================================================




More information about the asterisk-dev mailing list