Activating Methods

By default, Rexx assumes that an active method requires exclusive use of its scope variable (attribute) pool. If another method attempts access at that time, it is locked out until the first method finishes. This default intra-object serialization maintains the integrity of the instance variable (attribute) pool and prevents unexpected results. Rexx manages queues for incoming requests that result in messages being sent to the same object.

Some methods can run concurrently without affecting instance variable (attribute) pool integrity or yielding unexpected results. When a method does not need exclusive use of its object variable (attribute) pool, use the UNGUARDED option of the ::METHOD directive to provide unconditional intra-object concurrency. These mechanisms control the locking of an object's scope when a method is invoked.

Many methods cannot use the UNGUARDED option because they sometimes require exclusive use of their object variable (attribute) pool. At other times, they must perform some action that involves the concurrent use of the same pool by a method on another activity. In this case, you can use the GUARD keyword instruction. When the method reaches the point in its processing where it no longer requires exclusive use of the object variable (attribute) pool, it can use the GUARD OFF instruction to allow methods running on different activities to become active on the same scope. If the method needs to regain exclusive use, it uses the GUARD ON instruction.

For more flexibility when activating methods, you can use GUARD ON/OFF with the "WHEN expression" option. Add this instruction to the method code at the point where exclusive use of the object variable (attribute) pool becomes conditional. When processing reaches this point, Rexx evaluates expression to determine if it is true or false.

For example, if you specify "GUARD OFF WHEN expression", the active method keeps running until expression becomes true. To become true, another method must assign or drop an object variable (attribute) that is named in expression. Whenever an object variable (attribute) changes, Rexx reevaluates expression. If expression becomes true, GUARD is turned off, exclusive use of the object variable (attribute) pool is released, and other methods needing exclusive use can begin running. If expression becomes false again, GUARD is turned on and the active method regains exclusive use.

Note

If expression cannot be met, GUARD ON WHEN puts the program in a continuous wait condition. This can occur in particular when several activities run concurrently. A second activity can make expression invalid before GUARD ON WHEN can use it.