Var Bridge Object


VarBridge

The var bridge object stores data during run time, therefore it acts like a bridge to pass data between different threads. This object is also useful for joining threads. Data stored in a var bridge can be persistent, i.e. saved onto disk, or non persistent, i.e. lost when execution is stopped.

Normally all data a thread collects during run time is lost when a thread terminates. Passing data to a var bridge object stores the data so that other threads can access them. The data to be stored is specified via the property dialog. A single var bridge object can store an arbitrary number of variables. The contents of a var bridge can be cleared by calling the "clear" action.

When the "Join threads" option is checked in the property dialog, the behaviour is a little bit different: When a thread stores some data in the var bridge, the object checks whether all variables have data after the storing operation. If this is not the case, the calling thread is terminated. In the other case all data is copied to the output variables, the internal buffers are cleared and the thread continues execution. This is useful to collect data which has been calculated in parallel, but further on processing should continue in one single thread. This is especially useful when doing calculations on multi processor machines where it isn't known which thread terminates at first, or when thread execution time depends on external parameters.
Fig. 1: Two tasks where a var bridge is useful; note the dashed line in the "store data" case, which means that the "continue execution" option in the connection dialog has been switched off
Figure 1 shows examples of using the var bridge. In the left case the "DoSomthing2" object is called when the user presses a button. In this object data calculated by "DoSomthing" can be used, as it can be stored into the var bridge. The right example shows a layout where both "DoSomething" object execute parallel. The "Join threads" option must be checked in the var bridge object and the results of the two branches must be stored in two different variables. Then both variables care available for use in the "DoSomthing2" object. This is called when both of the "DoSomething" objects have finished processing. If the "Join threads" option is not checked in this case the "DoSomthing2" object would be called two times.

The normal type of a VarBridge is "Local", which means that data is neither persistent, i.e. written to disk, nor "Foreign", which means that it is got from another VarBridge object.

Persistent Mode

When VarBridge type is set to "Persistent", data is not only stored in memory but also onto disk. For each VarBridge object an own file is created onto disk containing the data of the var bridge object. The VarBridge's object title is used as a file name. So having different persistent VarBridge objects having the same filename they all use the same data file and all of them should contain the same variable definitions. When reading a data file containing a different variable list, an error message is create during execution and the read is aborted. The persistent data files are created in a directory which can be specified via the settings dialog in the options menu.
Fig. 2: Using a persistent var bridge
Figure 2 shows a usage example of a persistend var bridge object: Here it is used to restore the value of a scrollbar when the execution is switched on and off again. When the execution is startet, the scrollbar is initialized with the stored value. On each change of the scrollbar value it is stored in the var bridge and written to disk.

Foreign Mode

When VarBridge type is set to "Foreign", the data memory of a different VarBridge object with the same title is used. The two VarBridge objects then behave absolutly similar and always use the same copy of data. An automatic locking mechanism prevents that data is changed by one of the VarBridge objects when being read or written by the other VarBridge object. There can exist multiple "Foreign" VarBridge objects with the same title, all of them behaving similarly. But for each group of VarBridge objects there must only be one "Local" or "Persistent" object, as soon as a "Foreign" VarBridge object exists with the same title. Otherwise it would be undefined which of the VarBridge object's data memories is used.

When using a VarBridge object that gets its data from a "Persistent" VarBridge, reading and storing data is also done when calling the "Foreign" type VarBridge.


The Vimms User Manual