Jump to content
We have recently updated our Privacy Statement, available here ×
  • BW6.X - BWCE - Useful things to know about Module Shared Variables in BusinessWorks and BusinessWorks Container Edition


    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.

    1*7u_-IABuIiqwlDrAiLW2LA.png

    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.

    1*k9_RdMWzyOkd_iONpyzarA.png

    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.

    1*UzajcQdLej8tZqCcZuPjSw.png

    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.

    1*PE5G4V8qAv08ywx2BXhv2Q.png

    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.

    Additional elements

    A sample project is attached to this article.

    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

    Additional elements

    You can refer to the attached sample project.

    SharedVariableAccess.zip


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...