Useful things to know about Module Shared Variables in BusinessWorks and BusinessWorks Container Edition

Emmanuel Marchiset
3 min readMar 17, 2024

--

It is quiet common for BusinessWorks developers to encounter difficulties in understanding when Module Shared Variables can be accessed directly and when it is necessary to use a Critical Section.

This article goal is to bring needed clarifications on this topic.

Module Shared Variables can be shared between multiple processes definitions and multiple process instances. Because of the multi-threaded nature of the BusinessWorks engine there are some cases where it is necessary to use Critical Sections.

One important thing to know is that accesses to a given Module Shared Variable, using the ‘Get Shared Variable’ and ‘Set Shared Variable’ activities, are synchronized.

Reading or setting the value of a Module Shared Variable

This means that for just reading the current value of a Module Shared Variable, at the moment of the Process execution, it is possible to just use the ‘Get Shared Variable’ activity without using a Critical Section.

Reading the current value of a Module Shared Variable

This means also that for just setting the value of a Module Shared Variable without taking care of its current value it is possible to just use the ‘Set Shared Variable’ without using a Critical Section.

Setting the value of a Module Shared Variable

Updating the value of a Module Shared Variable in a process

In the case of a process that needs to read the current value of a Module Shared Variable and update it, for example to increase a counter or update some king of semaphore flag, it is necessary to use a critical section while multiple instances of this Process might be executing and accessing the variable at the same time. In such case the ‘Get Shared Variable’ and ‘Set Shared Variable’ activities must be included in a Critical Section.

Updating the value of a Module Shared Variable

Updating the value of a Module Shared Variable in different processes

It is also possible for different process definitions to update the same Module Shared Variable using a different logic.

In that case it is necessary to use a Critical Section in each of the process definitions and to synchronize them using the Module Shared Variable. This can be done by checking the ‘Shared Lock’ option and selecting a Module Shared Variable. The selected Module Shared Variable is then used as a semaphore to control execution of the different Critical Sections referring to it.

Using a Shared Lock in a critical section

Using a Module Shared Variable as a Semaphore

The approach to use multiple critical sections synchronized with a Module Shared Variable can also be used to manage accesses to external resources like for example a file, in such case a Critical Section with a Shared Lock can be used to manage concurrent accesses to the target file from different processes of an application.

Accesses to Job Shared Variables

Job Shared Variables are local to a process instance and there is no need to use Critical Sections to access them except in case where the same Job Shared Variable would be updated in parallel branches of a process definition.

Elements for BusinessWorks 5.X

The elements provided in this article also applies to BusinessWorks 5.X except that the ‘Shared Lock’ mechanism is not available in BusinessWorks 5.X.

Reference elements

https://docs.tibco.com/pub/activematrix_businessworks/6.10.0/doc/html/Default.htm#app-dev-guide/working-with-critica.htm

https://docs.tibco.com/pub/activematrix_businessworks/6.10.0/doc/html/Default.htm#binding-palette/critical-section.htm

--

--

Emmanuel Marchiset

I work as an Architect at TIBCO Software on Integration products. Opinions here are my own.