Activating Methods

By default, REXX assumes that an active method requires exclusive use of its object variable pool. Should another method attempt access at that time, it is locked out until the first method is done with the variable pool. This default intra-object concurrency maintains the integrity of the variable pool and prevents unexpected results. The intra-object concurrency support is especially useful in coding servers. You don't need to manage queues for incoming requests that result in messages being sent to the same object. REXX does it for you.

Some methods can function concurrently without affecting the variable pool integrity or yielding unexpected results. When a method does not need exclusive use of its object variable pool, you can use the SETUNGUARDED method or 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 SETUNGUARDED and UNGUARDED simply because they require exclusive use of their variable pool some of the time. At other times, they need to perform some action which will involve the concurrent use of the same pool by a method on another activity. In this case, you can use the GUARD instruction. Using the GUARD instruction, when the method reaches the point in its processing where it requires concurrent use of the variable pool, it invokes GUARD OFF. GUARD OFF lets another method running on a different activity become active on the same object. If the method needs to regain exclusive use, it invokes GUARD ON.

For even 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 variable 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 issuing method waits until expression becomes true. To become true, another method must assign or drop an object variable that is named in expression. Whenever an object variable changes, REXX reevaluates expression. If expression becomes true, exclusive use of the variable pool is released (because GUARD OFF was specified) and the issuing method resumes with the next instruction.


[Back: Programming for Intra-Object Concurrency]
[Next: Computer Karaoke--A REXX Concurrency Sample]