Conceptually, each Rexx object is like a small computer with its own processor to run its methods, its memory for object and method variables, and its communication links to other objects for sending and receiving messages. This is object-based concurrency. It lets more than one method run at the same time. Any number of objects can be active (running) at the same time, exchanging messages to communicate with, and synchronize, each other.
Early reply provides concurrent processing. A running method returns control, and possibly a result, to the point from which it was called; meanwhile it continues running. The following figure illustrates this concept.
Method A includes a call to Method B. Method B contains a REPLY instruction. This returns control and a result to method A, which continues processing with the line after the call to Method B. Meanwhile, Method B also continues running.
The chains of execution represented by method A and method B are called activities. An activity is a thread of execution that can run methods concurrently with methods on other activities.
An activity contains a stack of invocations that represent the Rexx programs running on the activity. An invocation can be a main program invocation, an internal function or subroutine call, an external function or subroutine call, an INTERPRET instruction, or a message invocation. An invocation is activated when an executable unit is invoked and removed (popped) when execution completes. In the Early Reply figure, the programs begins with a single activity. The activity contains a single invocation, method A. When method A invokes method B, a second invocation is added to the activity.
When method B issues a REPLY, a new activity is created (activity 2). Method B's invocation is removed from activity 1, and pushed on to activity 2. Because activities can execute concurrently, both method A and method B continue processing. The following figures illustrate this concept.
Here is an example of using early reply to run methods concurrently.
/* Example of early reply */ object1 = .example~new object2 = .example~new say object1~repeat(10, "Object 1 running") say object2~repeat(10, "Object 2 running") say "Main ended." exit ::class example ::method repeat use arg reps,msg reply "Repeating" msg"," reps "times." do reps say msg end