FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [April 2006 Threads] Deleting the Running taskPosted by Nobody/Anonymous on April 1, 2006 If a task calls vTaskDelete() passing its own task handle rather than NULL, then there can be a problem. This is because the final taskYIELD() is not called. I fixed it by putting the following within the critical section of the main body of vTaskDelete() after it gets the pointer to the TCB to delete:
if ((tskTCB *)pxTaskToDelete==pxCurrentTCB) pxTaskToDelete = NULL;
(Testing pxCurrentTCB must be protected.)
Although it may seem strange to call vTaskDelete() with the running task's handle, my situation was that it was being called from some common task cleanup code that was unaware if who was calling it. Of course, the fix could be at the point of call, but my feeling is that it best belongs in the vTaskDelete() function.
A point of interest - I found that the problem can manifest itself as intermittent. If an interrupt reschedules another task a just the right moment, then the taskYIELD() is, of course, unnecessary. It made for interesting debugging, because when I single stepped through vTaskDelete() everything worked fine, but normally it it didn't.
... I use the ARM7 port.
RE: Deleting the Running taskPosted by Richard on April 1, 2006 The original thinking on this was that a task should not delete itself by passing in its own handle, but as you point out there is nothing stopping it from doing this. Passing in NULL forces the application designer to specifically say "I really mean to do this".
In your case, does the generic clean up code know it is deleting itself. If it is deleting all the tasks in the system then it will have to delete itself last.
I think you are right that this needs to be more specific, the question is should:
1) Passing in the current task handle cause the function to return without doing anything. The rationale being that you have passed in an invalid input as NULL is the only way of guaranteeing the current task gets deleted.
2) Passing in the current task handle causes the current task to be deleted reliably.
I'm with you on my preference for 2) so have added the following code as per your suggestion:
/* Ensure a context switch will occur if the task being deleted is the calling task but NULL was not used as the parameter. */ if( pxTaskToDelete == pxCurrentTCB ) { ____pxTaskToDelete = NULL; }
Thanks for your contribution.
Regards.
RE: Deleting the Running taskPosted by Glen B. on April 28, 2006 I have just integrated FreeRTOS 4.0.1 into my project, and have discovered that this fix is not in.
Richard, was this an oversight, or did you change your thinking on it?
RE: Deleting the Running taskPosted by Richard on April 29, 2006 Sorry - oversight. I have added it to the list (again).
Regards.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|