Synchronized

Synchronized is used in a TurboIntegrator script to force serial execution of a designated set of TurboIntegrator processes.

This function is valid in TurboIntegrator processes only.

Syntax

The Synchronized function uses the following syntax.

Synchronized (lockName);

Synchronized takes a single required parameter that is a user-defined name for a lock object. This lock object name can be used in multiple TurboIntegrator processes in order to serialize their execution as a group.

Table 1. Synchronized arguments
Argument Description

lockName

The user-defined name of a lock object on which to synchronize. Names are case-insensitive and embedded spaces are ignored. Names may not exceed 1023 characters in length.

String/Yes/None

Semantics

A TurboIntegrator process may make any number of calls to Synchronized, with any number of lock objects. Serializing is effective from the time synchronized is called, until the containing transaction completes.

For example, if Synchronized is called from a subprocess (Ps) of primary process (Pp) or primary chore (Cp), the Lock Object is released when Pp or Cp completes. The exception is that a SaveDataAll (SDA) prematurely ends a transaction mid-process execution; this applies to Lock Objects as well.

The Synchronized call can be placed anywhere within a TurboIntegrator script, but serialization applies to the entire TurboIntegrator process when it is encountered.

Consider a TurboIntegrator process with a Synchronized call somewhere in the middle of its script, and an operation O1 preceding that call. Two instances of this TurboIntegrator process may start at the same time. It is possible for one instance to run to completion, including its call to Synchronized, before the second instance reaches its Synchronized call. In this case, the two processes appear to the user to have run concurrently. If, instead, the second process does reach its synchronized() call before the first completes, it will undo any work it had done (O1) and wait for the first to complete. In this case, the two processes appear to the user to have serialized.

To avoid such confusion, and to optimize the use of Synchronized, it is recommended (but not enforced) that Synchronized calls be the first statements of a TurboIntegrator process.

Example

Consider that TurboIntegrator process P needs to update two cubes, Cube_1 and Cube_2.

Other TurboIntegrator processes may also need to update Cube_1 or Cube_2.

To cause all TurboIntegrator processes that will update Cube_1 or Cube_2, to run one at a time, P could call Synchronized in this manner:

sCube_1='Cube_1';
sCube_2='Cube_2';
sE1='Elm1';
sE2='Elm2';
sE4='Units';
sE5='Price';

Synchronized( sCube_1 );
Synchronized( sCube_2 );

CellPutn( 111, sCube_1, sE1, sE2 );
CellPutn( 9.99, sCube_2, sE4, sE5 );

# ...

Other TurboIntegrator processes that will update Cube_1 or Cube_2 must also call Synchronized( sCube_1 ) and/or Synchronized( sCube_2 ) in a similar way.

In this example, the two lock objects' names were chosen to be the same as the cubes' names. But a lock object's name does not have to be the same as other objects (cubes, dimensions, subsets).