Assigning and Retrieving the Variable’s Value
You can retrieve the current value of a shared variable by using the Get Shared Variable activity. You can assign a value to the shared variable by using the Set Shared Variable activity. Both of these activities can be found in the General Activities palette.
Before you retrieve the value of a shared variable, you must either set an initial value in the variable’s configuration or use the Set Shared Variable activity to set the variable value. You can also configure the Set Shared Variable activity to include the current value of the variable as output for the activity. This provides access to the variable’s current value in subsequent activities in the process definition.
Synchronizing Access to Shared Variables
Because multiple process instances can potentially access and assign values to Shared Variable resources, the Lock shared configuration object and critical section group allow you to synchronize access to Shared Variable resources. Without a mechanism for locking, a process instance could update the value of a variable while another process instance is attempting to read the value. This would result in an unpredictable value for the variable.
You should use critical section groups to contain the Set Shared Variable and Get Shared Variable activities. This ensures that only one process instance attempts to assign a value to the variable and ensures that no process assigns a value to the variable when the current process attempts to read the value.
For more information about using the critical section group, see Critical Section Groups.