AGI Thread Safe

Here’s an interesting thought. I don’t know if it’s a function of Asterisk or the scripting language being used, but I see you can execute all the dial plan commands from within an AGI script. Dial, Queue and so on. I wonder if this is thread safe? That is, if the scripting language supports threads, and you started two threads, and each say, called Dial on a different user. Would that work, and would it be safe? I wonder if Asterisk would just block on the first thread it sees, and not allow the second to talk to it until the first was finished. It would be an interesting experiment. You could simulate SIP proxy forking with this, or do other neat stuff.

Hmmm… wait a sec. Each thread would have to write to stdout, which means they are both really communicating over the same output stream. Asterisk would receive the commands in no set order, and would execute them sequentially. I guess the question is then, what happens when dial command is received. Firstly, does asterisk return control? If it does, what happens if another Dial command comes in before the first has completed/timed out? Does it execute that second dial command concurrently with the first?

Are you on drugs? :wink:

Your second paragraph pretty much answers the first one: regardless of how many threads your language supports Asterisk receives the AGI commands in a given order through the communication stream and processes them in that order.

Each AGI command returns a reply when it has finished. Once an AGI command has finished and the reply has been sent, Asterisk reads the next command from the stream and processes it. One by one. Very simple.

srt, No. Not very simple. Are you sure that a dial command doesn’t return control until a command is completed?

Yes, I am.