Initiation of a coroutine consists of setting up a separate stack, passing any parameters (call-by-name or call-by-value), and beginning the execution of the procedure.
Processing of the initiating program, called the initiator or the primary coroutine, is suspended.
If the called procedure, referred to as the secondary coroutine, is a typed procedure, the return value is discarded. If the procedure identifier is a system-supplied process, such as an intrinsic, the library GENERALSUPPORT must be declared using a library entry point specification. The procedure identifier must be declared in the program or the syntax error, PROCEDURE MUST BE USER DECLARED, results. The actual parameter part must agree in number and type with the formal parameter part in the declaration of the procedure; otherwise, a run-time error occurs.
The task designator associates a task with the coroutine at initiation; the values of the task attributes of that task, such as COREESTIMATE, STACKSIZE, and DECLAREDPRIORITY, can be used to control the execution of the coroutine. For more information about assigning values to task attributes, refer to <arithmetic task attribute> under Arithmetic Assignment, and <Boolean task attribute> under Boolean Assignment and Task Assignment.
Every coroutine has a partner task to which control can be passed by using the CONTINUE statement. The partner task of the secondary coroutine is the initiator by default but can be changed by assignment to the task-valued task attribute PARTNER of the task designator. To determine if the current partner process is in a state to be CONTINUEd, a process can interrogate the PARTNEREXISTS task attribute. Local variables and call-by-value parameters of the secondary coroutine retain their values as control is passed to or from the coroutine. For more information about the PARTNER and PARTNEREXISTS task attributes, refer to the Task Management Programming Guide.
The critical block, described in PROCESS Statement, in the initiator cannot be exited until the secondary coroutine is terminated. Any attempt by the initiator to exit that block before the secondary coroutine is terminated causes the initiator and all tasks it has initiated through CALL or PROCESS statements to be terminated.
A secondary coroutine is terminated by exiting its own outermost block or by execution in the initiator of the following statement, where the task designator specifies the task associated with the secondary coroutine to be terminated:
<task designator>.STATUS:= VALUE(TERMINATED)
| Note: | The CALL statement causes the initiation of a separate stack as a coroutine. Because of the cost involved, a coroutine should be established once and then used through CONTINUE statements. If a CALL statement is used to invoke a procedure, overall system efficiency is severely degraded. A string expression cannot be passed as an actual parameter to a call-by-name parameter of a procedure in a CALL statement. |

