Oberon || Library || Module Index || Search Engine || Definition || Module
CONST taskGroupMismatch = 0; CONST dispatchTerminatedTask = 1; CONST wrongScheduler = 2; CONST invalidSet = 3; CONST errorcodes = 4; TYPE ErrorEvent = POINTER TO ErrorEventRec; TYPE ErrorEventRec = RECORD (Events.EventRec) errorcode: SHORTINT; END; VAR errormsg: ARRAY errorcodes OF Events.Message; VAR error: Events.EventType;
TYPE Task = POINTER TO TaskRec; TYPE TaskRec = RECORD (Disciplines.ObjectRec) END; TYPE TaskGroup = POINTER TO TaskGroupRec; TYPE TaskGroupRec = RECORD (Disciplines.ObjectRec) END;
(* codes returned by the dispatch procedure *) CONST terminate = 0; CONST suspend = 1; CONST waitfor = 2;
TYPE CreateProc = PROCEDURE (VAR task: Task; cr: Coroutines.Coroutine);
PROCEDURE Current() : Task; PROCEDURE CurrentGroup() : TaskGroup;
PROCEDURE InitGroup(tg: TaskGroup); PROCEDURE Init(task: Task; cr: Coroutines.Coroutine; tg: TaskGroup); PROCEDURE Dispatch(tg: TaskGroup; task: Task; setOfTrueConditions: Conditions.ConditionSet; VAR code: SHORTINT; VAR conditionSet: Conditions.ConditionSet);
PROCEDURE Suspend; PROCEDURE Select(conditionSet: Conditions.ConditionSet; VAR setOfTrueConditions: Conditions.ConditionSet); PROCEDURE WaitForOneOf(conditionSet: Conditions.ConditionSet); PROCEDURE WaitFor(condition: Conditions.Condition); PROCEDURE Terminate; PROCEDURE Disconnect;
PROCEDURE Create(VAR task: Task; cr: Coroutines.Coroutine); PROCEDURE SetupDefaultGroup(create: CreateProc);
Tasks are in one of four states:
Select, WaitForOneOf, and WaitFor cause a state transition from running to waiting until one of the given conditions becomes TRUE (see Conditions). Then the state will change from waiting to ready. Select returns the set of true conditions in setOfTrueConditions. Note that neither Select nor WaitForOneOf accept an empty condition set or NIL.
Suspend causes a state transition from running to ready.
Terminate is the final point of no return of a coroutine. Note that the procedure body of a coroutine must not return and that coroutines can only terminate themselves.
Alternatively, if Disconnect is used instead of Terminate, the task is still considered terminated but the coroutine may be switched to again and/or assigned to a new task.
Current returns the current task and CurrentGroup the current task group.
A scheduler (usually represented by a module) consists of three parts:
Additionally, group members should be allowed to create new members. The procedure which represents the scheduler should return to the calling procedure if all members are terminated but should not terminate itself.
A new task group is to be initialized by InitGroup. Note that the allocation of tg is to be done in advance because most schedulers need an extension of TaskGroup. The current task becomes the scheduler of the new task group.
Init initializes a new task and associates it with a coroutine and a task group. The coroutine must have been created in advance but from the viewpoint of Tasks it does not matter whether the coroutine was already running or not. Init initializes the errors component of the task and calls RelatedEvents.QueueEvents for it. Task related errors errors should be related to the errors component instead to the task itself.
The task which represents the scheduler is free to select one of its group members and to dispatch it by a call to Dispatch. Dispatch returns code and, if code equals waitfor, the associated conditionSet:
Terminate, Suspend and Select determine the return values of Dispatch (code and conditionSet) and return to the scheduler of the current task group.
Oberon || Library || Module Index || Search Engine || Definition || Module