Oberon || Library || Module Index || Search Engine || Definition || Module

Ulm's Oberon Library:


Schedulers - general scheduler interface


TYPE TaskGroup = POINTER TO TaskGroupRec;
TYPE TaskGroupRec = RECORD (Tasks.TaskGroupRec) END;
TYPE TaskRec = RECORD (Tasks.TaskRec) END;

TYPE DispatchProc = PROCEDURE (tg: TaskGroup; VAR task: Task); TYPE CreateProc = PROCEDURE (tg: TaskGroup; VAR task: Task); TYPE RemoveProc = PROCEDURE (tg: TaskGroup; task: Task); TYPE Interface = POINTER TO InterfaceRec; TYPE InterfaceRec = RECORD dispatch: DispatchProc; create: CreateProc; remove: RemoveProc; END;

CONST badTask = 0; CONST failureOfWaitFor = 1; CONST errorcodes = 2; TYPE ErrorEvent = POINTER TO ErrorEventRec; TYPE ErrorEventRec = RECORD (Events.EventRec) errorcode: SHORTINT; END; VAR errormsg: ARRAY errorcodes OF Events.Message; VAR error: Events.EventType;

PROCEDURE InitGroup(tg: TaskGroup; if: Interface); PROCEDURE StartScheduler(tg: TaskGroup); PROCEDURE AddTask(tg: TaskGroup; cr: Coroutines.Coroutine; VAR task: Tasks.Task); PROCEDURE Ready(task: Task) : BOOLEAN;


Schedulers realizes an interface for schedulers. The main work (condition processing and error handling) of schedulers is already done by Schedulers -- the only task which is left open to an implementor is the selection of one of the ready tasks.

InitGroup initializes a new task group and associates it with the given interface if. The interface procedures are expected to meet following specifications:

dispatch: PROCEDURE(tg: TaskGroup; VAR task: Task);
select one of the ready tasks of tg and return it in task. Schedulers guarantees that at least one task is ready for execution.

create: PROCEDURE(tg: TaskGroup; VAR task: Task);
create and initialize task and add task to the list of tasks which belong to tg. This interface procedure allows to get track of the current list of tasks.

remove: PROCEDURE(tg: TaskGroup; task: Task);
remove task from the list of tasks.

StartScheduler starts the scheduling algorithm and returns in case of fatal errors or if all tasks which belong to tg are terminated. StartScheduler calls Tasks.WaitFor with the union of all waiting conditions if all tasks are waiting. This causes the current process to be blocked if StartScheduler has been called by the main task. Note that StartScheduler may be called even if the initial task group is empty. In this case, StartScheduler waits for the first task being added by AddTask and starts afterwards the scheduling algorithm.

AddTask creates a new task which represents cr and includes it in the set of tasks which belong to tg. Further, every task is free to call AddTask while StartScheduler is running.

Ready returns TRUE if task is currently not waiting.


Following errors lead to events which are related to the task group and passed to RelatedEvents. Further, StartScheduler returns immediately in case of such errors.
The task which has been selected by dispatch is not ready or does not belong to the task group.
Indicates that Tasks.WaitFor returned too early, i.e. none of the conditions evaluates to TRUE or causes a failure.
Errors which result from failures to evaluate a condition are forwarded to the errors components of all tasks which waits for the given condition.


interface for conditions
error handling
creates the main task group
popular scheduler on top of this module
general task management

Edited by: borchert, last change: 2001/05/17, revision: 1.6, converted to HTML: 2001/05/17

Oberon || Library || Module Index || Search Engine || Definition || Module