Home |
RTKernel-32 Programming Manual Function RTKTerminateTask |
Function RTKTerminateTaskFunction RTKTerminateTask normally does not need to be called. The natural termination of a task occurs when the task returns from its task function. Only the Main Task terminates all tasks (i.e., the whole program) when it reaches the end of function main, or when function exit is called. void RTKTerminateTask(RTKTaskHandle * Handle); ParametersHandleA pointer to a task handle identifying the task to be terminated. It must have been assigned a valid value by RTKCreateThread or RTKCurrentTaskHandle. If an invalid value is passed to RTKTerminateTask, the program is aborted with an error message. Handle is assigned the value RTK_NO_TASK. Prior to actually terminating the task, RTKernel-32 makes sure the task is not occupying a resource or mutex semaphore. If this is the case, the task continues to run until all resources have been released. The task calling RTKTerminateTask does not wait until task termination has been completed, but continues to run immediately. Stack and TCB of the task to be terminated are deallocated, provided that *Handle does not reference a currently running task. The memory of a task terminating itself is released by the next call to RTKCreateThread, RTKRTLCreateThread or RTKDeallocTerminatedTasks. Until then, the task still exists in the state Terminated; however, it cannot run any more. Care should be taken that a task is not terminated twice (e.g., by itself and another task), because the task would not exist any more when RTKTerminateTask is called the second time. In this case, RTKernel-32 would abort the program with an error message since the handle would have an illegal value. Threads created with RTKRTLCreateThread should not be terminated with RTKTerminateTask, because resources allocated by the run-time system for the thread would not be deallocated. Instead, such threads should return from their thread function or they should call whatever terminating function is made available by the tun-time system. As in sequential programs, function exit can be called at any time to terminate the program. However, function abort should be avoided because it does not restore the interrupt vectors.
|