The scrinst instruction determines the number of instances of a script currently running on the system.
Synopsis
scrinst([ctype.script])
Description
The scrinst instruction enables an application script to find out how many instances of a script are running currently on the system. Based on the value returned by this instruction, the script may choose to prohibit execution of another instance of the script (using the exec instruction) or the script may quit if it is performing a check on itself and has exceeded the limit.
The ctype.script optional argument is the script or service name. If no script name is given, the script executing the instruction is assumed. This instruction sets the value of register 0 (r.0) to the number of instances of the given script at the time the instruction is invoked.
There are several possible uses of scrinst based on the ways in which a script may be started:
Incoming call |
It is suggested that the method of limiting the number of scripts started with an incoming call be left as it is. That is, do not assign a service to a number of channels greater than the desired limit. If the number of channels assigned to a script exceeds the limit, a script still may check the instance count as its first task and quit before answering the call if the instances exceed the limit. |
exec |
The exec script instruction is the primary means by which an instance limit may be exceeded. Therefore, any application script that is concerned about running too many instances of another script should use scrinst for that script before using exec. In this case, it is important to avoid a wait condition in the interval between scrinst and exec. This could cause other scripts running simultaneously that are performing the same test to get identical results from scrinst before any of them perform the exec instruction. Use tflush before scrinst to play any speech that is queued. Otherwise, the exec instruction plays the speech and the script waits for the play to complete before performing the exec instruction. |
Soft seizure and virtual seizure |
Scripts started by a soft seizure or virtual seizure request from a DIP may use scrinst to check themselves against an instance limit as their first task, similar to the way scrinst may be used if the script is started by an incoming call. If the script determines that it cannot continue, it may signal the DIP that started it by using the dipterm instruction and calling quit with a specific value that the DIP may check. |
Examples
In the first example, the script requests the number of instances of the script riverbank currently running on the system. In the second example, because no argument is given, the script requests the number of instances of itself running on the system.
scrinst("riverbank")
scrinst()