Sorry if this appears twice - I originally sent it nearly 18 hours ago and never saw it .. I have a need to have a unique integer number that can be used by a dynamic meetme room (I am wanting to redirect a call into a meeting room, and need a unique number to make sure I don't put two people together !) I was going to use a global variable ${NEXTMEETME}, and add one every time I redirect. Is the changing of a global variable atomic ? That is, if I have two or more channels being redirected at the same time, and they all execute exten => _X.,n,Set(NEXTMEETME=${MATH(${NEXTMEETME}+1,i)}) exten => _X.,n,Set(MYMEETME=${NEXTMEETME}) if NEXTMEETME is initially 0, would channel A get MYMEETME as 1, channel B get 2 and channel C get 3, even if they execute the dialplan at the same time ? Julian.
Julian Lyndon-Smith wrote:> Sorry if this appears twice - I originally sent it nearly 18 hours ago > and never saw it .. > > I have a need to have a unique integer number that can be used by a > dynamic meetme room (I am wanting to redirect a call into a meeting > room, and need a unique number to make sure I don't put two people > together !) > > I was going to use a global variable ${NEXTMEETME}, and add one every > time I redirect. > > Is the changing of a global variable atomic ? That is, if I have two or > more channels being redirected at the same time, and they all execute > > exten => _X.,n,Set(NEXTMEETME=${MATH(${NEXTMEETME}+1,i)}) > exten => _X.,n,Set(MYMEETME=${NEXTMEETME}) > > if NEXTMEETME is initially 0, would channel A get MYMEETME as 1, channel > B get 2 and channel C get 3, even if they execute the dialplan at the > same time ? >Someone more knowledgeable about Asterisk than I can correct me, but I would look at it from the perspective any development environement: Global variables are typically bad in a threaded environment without some form of queuing/locking/critical section functionality to avoid collisions. If I needed a globally unique, sequential number, I'd push it out to AGI/FastAGI so I could use a language with support for locking/queuing. A DB like MySQL or FirebirdSQL would easily handle this need as you know, but then is the overhead of establishing DB connections worth it for simply getting a incremented int? -- Warm Regards, Lee
>The contents of this e-mail are intended for the named addressee only. It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or disclose it to anyone else. If you received it in error please notify us immediately and then destroy it.> From: asterisk-users-bounces at lists.digium.com > [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of > Julian Lyndon-Smith > Sent: Saturday, July 28, 2007 5:18 AM > To: asterisk-users at lists.digium.com > Subject: [asterisk-users] global variables and updates > > Sorry if this appears twice - I originally sent it nearly 18 > hours ago > and never saw it .. > > I have a need to have a unique integer number that can be used by a > dynamic meetme room (I am wanting to redirect a call into a meeting > room, and need a unique number to make sure I don't put two people > together !) > > I was going to use a global variable ${NEXTMEETME}, and add one every > time I redirect. > > Is the changing of a global variable atomic ? That is, if I > have two or > more channels being redirected at the same time, and they all execute > > exten => _X.,n,Set(NEXTMEETME=${MATH(${NEXTMEETME}+1,i)}) > exten => _X.,n,Set(MYMEETME=${NEXTMEETME}) > > if NEXTMEETME is initially 0, would channel A get MYMEETME as > 1, channel > B get 2 and channel C get 3, even if they execute the dialplan at the > same time ? >The changing of variables is not atomic as would hope, but there is a solution for you. Look the application MacroExclusive. Put your Set to increment the global variable inside of a macro and call it using this, and you will get the behavior you desire. One caveat, however, is that you will want as little logic as possible inside of this macro. MacroExclusive will block all other calls to this macro until the first one exits. But this is not an issue if all you are doing is a quick var++ and then leaving. - Brad
Thanks for all the replies and help - For future reference I eventually decided to go for a func_odbc solution and use a database sequence that *is* atomic and gives me what I needed. Julian. Julian Lyndon-Smith wrote:> Sorry if this appears twice - I originally sent it nearly 18 hours ago > and never saw it .. > > I have a need to have a unique integer number that can be used by a > dynamic meetme room (I am wanting to redirect a call into a meeting > room, and need a unique number to make sure I don't put two people > together !) > > I was going to use a global variable ${NEXTMEETME}, and add one every > time I redirect. > > Is the changing of a global variable atomic ? That is, if I have two or > more channels being redirected at the same time, and they all execute > > exten => _X.,n,Set(NEXTMEETME=${MATH(${NEXTMEETME}+1,i)}) > exten => _X.,n,Set(MYMEETME=${NEXTMEETME}) > > if NEXTMEETME is initially 0, would channel A get MYMEETME as 1, channel > B get 2 and channel C get 3, even if they execute the dialplan at the > same time ? > > Julian. > > _______________________________________________ > --Bandwidth and Colocation Provided by http://www.api-digital.com-- > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users > > ______________________________________________________________________ > This email has been scanned by the MessageLabs Email Security System. > For more information please visit http://www.messagelabs.com/email > ______________________________________________________________________ > > ______________________________________________________________________ > This email for dotr.com has been scanned by MessageLabs > ______________________________________________________________________ > >