Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Deleting the Running task

Posted 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 task

Posted 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 task

Posted 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 task

Posted by Richard on April 29, 2006
Sorry - oversight. I have added it to the list (again).

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists