Threads and Bubbles

VTScada 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.

Bubbles are similar to threads, except that the code running within a bubble can run completely in parallel with the code that is running outside the bubble, taking better advantage of the CPU resource: code inside the bubble can run on one processor core while the script code running outside the bubble runs on another processor core.

If you do not use additional bubbles and just use threads, your script code can use at most one processor core. Using script threads makes it easier to interleave the execution of multiple processes within VTScada, but the use of bubbles makes it possible for those processes to run fully in parallel across multiple processor cores.

Thread or Bubble?

Bubbles are useful when there are multiple independent processes running at the same time that are CPU-bound. That is, the sum of these processes would consume more than one CPU core for a period of time. If you do not use additional bubbles and just use threads, your script code can use only one processor core. Processes running on different processor cores will not hold each other up as much as when they are all funneled through a single core. Consequently, those processes may complete more quickly and you may be able to run more such processes at once. Also, if a CPU-intensive process has been offloaded into a bubble, then it will not reduce user-interface responsiveness of code running outside that bubble

Interaction between the code running in two bubbles is highly controlled, and only permitted through a messaging interface. As a result, bubbles have the additional feature of isolating code to limit its ability to interact with other code in the system, which can be a useful security feature.

However, there can be significant overhead to starting a bubble as well as communicating data into and out of that bubble. While running, bubbles have significantly more memory overhead than threads. Bubbles work best when the ratio of work to inter-bubble communication is high. Also, certain VTScada features are not supported in user-created bubbles. (List provided later within this topic.)

Using script threads makes it easier to interleave the execution of multiple processes within VTScada, but the use of bubbles makes it possible for those processes to run fully in parallel across multiple processor cores.

Using Threads

A threaded module is like a launched module, except each will run in its own thread. Use only when there is a clear need. Each new thread imposes additional overhead on the CPU and RAM. Launching many threaded modules will slow your overall application.

To launch a threaded module, use the Thread() function.

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.

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 ODBC and TODBC.

The VTScada Source Debugger and the Thread List Application provide tools to assist you in troubleshooting threading within your applications.

Using Bubbles

VTScada script code is always operating within a bubble, referred to as the system bubble. From this top-most bubble, you can start child bubbles and they can start their own child bubbles, forming a tree of bubbles.

The following VTScada features must run only in the system bubble and are unsupported in child bubbles.

TAPI

Includes the functions, ModemCount, ModemStream, ModemDial, ModemTransfer, ModemList, ModemDev, CallerID, ModemDigits, and ModemMedia

DDE

Client and server, as well as all DDE functions.

VTScada OPC server functions

Includes the functions OPCServer and SetOPCData.

Thin clients

Windows created within a bubble are visible only on the server, never on a thin client.

Thin client management

Includes the functions VICMessage, VICInfo, and SetVicParms.