Threading

VTS provides the ability to have multiple control threads that share a single address space, but appear to behave as if they were separate processes (i.e. the processing time is divided equally among threads of the same priority). This means that those statements that are deemed to be threaded, and any modules that are called in their own thread will not block each other waiting for their turn to execute, but will instead share the processor's time, giving the appearance of simultaneous execution.

The chapter Function Usage in States, Scripts, and Threading lists which functions are threaded. In cases where two versions of the same function exist, one being threaded and the other not, the threaded version will generally have a "T" appended to its name, such as in the case of Get and TGet.

Great care must be exercised in using threaded functions or in launching a module in its own thread by using the Thread statement (this is discussed further in the section on modules). Since each thread executes independently of the others, except for its shared memory space, no assumptions may be made as to when the statement is finished execution and its resultant variable assigned a value. Any variables set by threaded statements must be checked for validity before proceeding to use them. If order of execution is important and the task to be performed is not an overly long and arduous one, it may be better to use the non-threaded version of a function. For example, if you wish to retrieve ten thousand records from a file and don't want your entire application to be suspended while the data retrieval is happening, using a TGet is probably appropriate. If on the other hand you have only two records to retrieve (assuming that they don't each contain a thousand fields) you may find that Get is more appropriate, since any processing of the data can be included in the same script that executes the Get and there will not be any time wasted in creating and destroying the thread in which the function operates.

It should be noted that VTS provides utilities to assist you in troubleshooting threading in your applications. The Thread List described in Thread List supplies a list of the separate threads of execution for which VTS is responsible within a local application.