Listing 1 (schedcon.c) Scheduling Control Task

#include <synrtx.h>

static handler IdentifyTheCallerTask(msg_t *msg_ptr) { 
   register task_t caller = msg_ptr->srcTid;

   io_putf("Interrupted by task #%w named: %s\n", caller,
                                 task_nameOf(caller));
}
task SchedulingControl(void) {
   task_t       myChild, self;
   priority_t   myPriority;
   timeslice_t  myTimeslice;

   /* creation of a child named ChildTask, priority 1, timeslice 20ms */
   myChild = task_create(ChildTask, "ChildTask", 1, 20, NO_ARG, NO_VAR);

   /* print the child taskid in three different ways
   io_putw(myChild);
   io_putw(task_child());
   io_putw(task_idOf("ChildTask"));

   /* Start the execution of myChild */
   task_resume(myChild);

   /* Print my task id and my parent task id */
   io_putw(task_self());
   io_putw(task_parent());

   /* Save my priority and my time slice */
   self = task_self();
   myPriority = task_priorityOf(self);
   myTimeslice = task_timesliceOf(self);

   /* Raise my priority */
   task_setPriorityOf(self, myPriority + 1);

   /* Suspend my child, give him my old priority, and start him again */
   task_suspend(myChild);
   task_setPriorityOf(myChild, myPriority);
   task_resume(myChild);

   /* Raise my time slice by 10 real-time units */
   task_setTimesliceOf(self, myTimeslice + 10);

   /* Give up the cpu */
   task_reschedule();

   /* When get back here, kill my child, and suicide */
   task_terminate(myChild);
   task_terminate(self);
}