Page 1 of 1

OS_Destroy can not reuse TCBP

PostPosted: Wed May 09, 2007 1:56 am
by samuel
1. On p. 256 of the Salvo User's Manual it says that a task which kills itself using OS_Destroy() can not be restarted, but another task using the same TCBP can be put in its place. Is this correct?? I don't really see why another task can be put in its place but not the same task???

2. Also, listen to this example and tell me if I'm being risky. I have a task A that calls a subroutine B, and B calls OSDestroyTask( A ); Currently I'm doing this and it's working fine. Is this a risky move?

3. I've read in the forums and manual that a task waiting on an event can not be stopped or destroyed. What happens if I attempt this?


Re: OS_Destroy can not reuse TCBP

PostPosted: Wed May 09, 2007 2:13 am
by samuel
An update the example in part 2. The call to OSDestroyTask(A) in B actually wasn't doing anything, it was a call in A to OS_Destroy() that was causing the expected functionality. So I assume that you can't destroy a running task?? However, I changed the call in subroutine B to OS_Destroy() and I still got the expected the results. I assume that OS_Destroy() kills the running routine, regardless of where program execution is?

Re: OS_Destroy can not reuse TCBP

PostPosted: Wed May 09, 2007 2:15 am
by aek
1. You can re-put that same task in that tcb -- but you have to recreate the task first. IOW, once a task destroys itself, the tcb is invalid, and must be reinitialized.

2. That's risky (but functions) because after destroying the parent task, you still have to return to the scheduler, which will look to see if it needs to update said task's tcb. Not a great ide, but (without further looking into it on my part) it's probably OK.

3) Use this function to absolutely destroy a task:

code:
static void
RestartTask( OStypeTFP tFP, OStypeTcbP tcbP )
{
uint8_t i;

OSBeginCriticalSection();

OSDelDelay( tcbP );
OSDelPrioQ( tcbP, &OSsigQoutP );
OSDelPrioQ( tcbP, &OSeligQP );

for (i=1; i<=OSEVENTS; i++) {
OSDelPrioQ( tcbP, &(OSECBP(i))->tcbP );
}

OSEndCriticalSection();

OSCreateTask( tFP, tcbP, 1 );
}

***

This will unconditionally replace the task currently occupying the tcbP by the task pointed to by tFP.

For 3.2.4 and later.


------------------


Re: OS_Destroy can not reuse TCBP

PostPosted: Wed May 09, 2007 2:34 am
by aek
OS_Destroy() is a context switch and can only be called from a task, not a subroutine. OSDestroyTask() can be called from subroutines.

------------------

[This message has been edited by aek (edited May 10, 2007).]


Re: OS_Destroy can not reuse TCBP

PostPosted: Mon May 14, 2007 12:17 am
by samuel
If I have a task A that is delayed via OS_Delay(x) and then call OSCreateTask() on the delayed task, will the task just start back over from the beginning?? Or will it put the system into an invalid state?? I guess what I'm asking is if there are any side effects to this?

Re: OS_Destroy can not reuse TCBP

PostPosted: Mon May 14, 2007 1:19 am
by aek
If you re-create from inside said task (after its OS_Delay()) then that should be fine.

If you re-create it from somewhere else while it is delayed, than that will be a problem.

------------------