[asterisk-dev] Accessing a channel from different threads

Dmitry Andrianov dimas at dataart.com
Mon Oct 8 11:58:43 CDT 2007


Just curious, is there any protection against channel to be destroyed
(freed) between the moment I've got reference to it and managed to lock
chan->lock ? Or is there a coding guidelines making it impossible?

-----Original Message-----
From: asterisk-dev-bounces at lists.digium.com
[mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Tilghman
Lesher
Sent: Monday, October 08, 2007 8:37 PM
To: Asterisk Developers Mailing List
Subject: Re: [asterisk-dev] Accessing a channel from different threads

On Sunday 07 October 2007 14:38, Corrado Santoro wrote:
> I'm writing an Asterisk application and, for some reason, I need to
> access the same "ast_channel" from two different threads: one thread
> basically executes "ast_waitfor_nandfds" and the other thread
"ast_write".
>
> So I would like to ask if the access to the channel is thread-safe, or
I
> need e.g. a mutex to avoid inconsistencies.

You need to lock and hold the chan->lock mutex for any period that you
access
and/or change channel structure elements.  Note that if you access more
than
one channel lock at a time, you may need to use ast_mutex_trylock() in a
loop
to avoid possible deadlocks (since there is no locking order for
different
channels in place).

-- 
Tilghman

_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev



More information about the asterisk-dev mailing list