[asterisk-dev] ast_mutex_t usage

Alex Massover alex at jajah.com
Tue Mar 2 01:39:36 CST 2010


Hi,

Thank you for reply. Probably I was wrong and only one thread enters critical section concurrently.

> -----Original Message-----
> From: asterisk-dev-bounces at lists.digium.com [mailto:asterisk-dev-
> bounces at lists.digium.com] On Behalf Of Tilghman Lesher
> Sent: שבת 27 פברואר 2010 20:58
> To: Asterisk Developers Mailing List
> Subject: Re: [asterisk-dev] ast_mutex_t usage
> 
> On Friday 26 February 2010 15:19:41 Alex Massover wrote:
> > Hello,
> >
> > Let me rephrase the question, maybe someone will help me :)
> >
> > Is there any chance that ast_mutex in module will “miss”, for example
> > because of multiple processes (fork() in core maybe)?
> >
> > From: asterisk-dev-bounces at lists.digium.com
> > [mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Alex
> Massover
> > Sent: יום ה 25 פברואר 2010 19:58
> > To: asterisk-dev at lists.digium.com
> > Subject: [asterisk-dev] ast_mutex_t usage
> >
> > Hello,
> >
> > I have a custom module, that exports foo(), the problem is that foo()
> is
> > not safe-thread, i.e. calls to it should be serialized.
> >
> > I tried to do it with ast_mutex like following:
> >
> > AST_MUTEX_DEFINE_STATIC(mp);
> >
> > static int foo(…..)
> > {
> > ….
> > ast_mutex_lock(&mp);
> > [non-reentrant code here]
> > ast_mutex_unlock(&mp);
> > …..
> > }
> >
> >
> > But I still see  that [non-reentrant] part is entered more than once
> > concurrently. Each channel can call foo() only once in dialplan, so
> it
> > looks like other threads/channels are entering it.
> >
> > Do I miss something please? Maybe there’re a better ways to serialize
> a
> > calls to module function?
> 
> No, that's the correct way.  What's your evidence that the critical
> section is
> being entered concurrently?
> 
> --
> Tilghman Lesher
> Digium, Inc. | Senior Software Developer
> twitter: Corydon76 | IRC: Corydon76-dig (Freenode)
> Check us out at: www.digium.com & www.asterisk.org
> 
> --
> _____________________________________________________________________
> -- 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
> This mail was received via Mail-SeCure System.

This mail was sent via Mail-SeCure System.


More information about the asterisk-dev mailing list