The state of a task is determined partly by its own priority, and partly by the other tasks in the system and the interactions among them. A task can wait for other tasks to complete certain processing, at which point it resumes its own processing. Intertask communication is essential because it enables one task to notify another task on the waiting queue that an external event is complete.
If there are no external events, preemptive multitasking only takes place when tasks of equal priority are the highest priority tasks in the ready queue. If only one task has the highest-priority, only that task runs, and all other tasks wait until the task finishes or is replaced by another task with higher priority.
Yield()
call cedes its CPU time immediately to another task with the same priority. The Yield()
call, which neither takes arguments nor returns anything, is:
void Yield( void )
Yield()
. If there is no other task in the ready queue with equal priority, then the task that executes the Yield()
call immediately resumes processing.
int32 WaitSignal( uint32 sigMask )
WaitSignal()
to put your task to sleep.
WaitSignal()
is the basic wait call that a task uses to wait for a signal. The wait calls WaitIO()
and WaitPort()
are built on WaitSignal().
Each of these calls puts a task on the waiting queue to await a signal, an I/O request return, or a message. Once the signal, I/O request, or message is received, the task returns to the ready queue.
Err SetItemOwner( Item i, Item newOwner )
SetItemOwner()
call takes two arguments, the item number of the task whose ownership you wish to change (Item
), and the item number of the task that is to become the new parent (newOwner
). This routine returns an error code if an error occurs.A task must be the parent of a child task to change its ownership. If this call is successful, the child task's TCB is removed from the current task's resource table and placed in the parent task's resource table.
Changing Task Priorities
When a task first runs, its priority is set based on a field defined in its TCB data structure. You can change the priority (in the range of 10 through 199) of a task after it has been created by using this call:
int32 SetItemPri( Item i, uint8 newpri )
i
, is the item number of the task whose priority you want to change. The second argument, newpri
, is the new priority value that you want the task to have. The call returns the old or former priority of the task or an error code (a negative number) if an error occurred.A task can change its own priority by calling:
SetItemPri(CURRENTTASK->t.n_Item, newPriority);