Sharing variables while multithreading EXECs

If you are allowing concurrent execution of multiple EXECs (see Multithreading EXECs to the Normal, High, or Hot priority queues), GLOBAL variables might be accessed and modified by several EXECs concurrently.

MainView AutoOPERATOR does not serialize variable usage between IMFEXEC VGET and VPUT commands.

You are responsible for the contents of your SHARED or PROFILE pool. The IMFEXEC VENQ and VDEQ statements are provided to serialize any resource. They are especially useful for serializing the use of variables.

Potential use

You must take special care if a GLOBAL variable can be updated by different EXECs concurrently or if an EXEC that updates a GLOBAL variable executes multiple times concurrently due to the use of multithreading.

This situation could eventually lead to disastrous results.

This example EXEC updates GLOBAL variables; it uses a locking mechanism provided by the IMFEXEC VENQ command to avoid variable corruption.

Describing the example

This EXEC serializes a resource named ABENDCNT.

The site that uses this EXEC has set a standard saying that GLOBAL variables are serialized by using a resource name that is identical to the variable name.

All EXECs within the site must conform to the standard or variable integrity might not be maintained.

The EXEC obtains an exclusive ENQ on the resource, reads the variable from the SHARED pool, performs some operations on the variable, saves the variable back in the SHARED pool, releases the resource, and exits.

Example

The following examples show how to use VENQ and VDEQ to serialize variables.

REXX EXEC example:

/* REXX EXEC */
/*----------------------------------------------------------------*/
/* DOC GROUP(AOS) FUNC(AOSAMP) DESC(USING VENQ AND VDEQ) */
/* DOC DISP(YES) AUTHOR(JAC) */
/*----------------------------------------------------------------*/
'IMFEXEC VENQ 'ABENDCNT' EXC'
IF IMFCC NE 0 THEN EXIT(16)
'IMFEXEC VGET ABENDCNT'
.
.
.
ABENDCNT=ABENDCNT+1
'IMFEXEC VPUT ABENDCNT'
'IMFEXEC VDEQ 'ABENDCNT''
IF IMFCC NE 0 THEN EXIT(16)
'IMFEXEC EXIT CODE(0)'

CLIST example:

PROC 0
/*********************************************************************/
/* DOC GROUP(AOS) FUNC(AOSAMP)  DESC(USING VENQ AND VDEQ)            */
/* DOC DISP(YES)  AUTHOR(JAC)                                        */
/*********************************************************************/
IMFEXEC VENQ 'ABENDCNT' EXC
IF &IMFCC NE 0 THEN EXIT(16)
IMFEXEC VGET ABENDCNT
.
.
.
SET ABENDCNT=&ABENDCNT+1
IMFEXEC VPUT ABENDCNT
IMFEXEC VDEQ 'ABENDCNT'
IF &IMFCC NE 0 THEN EXIT(16)
IMFEXEC EXIT CODE(0)

This version of the documentation is no longer supported. However, the documentation is available for your convenience. You will not be able to leave comments.

Comments