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


Delete Tasks

Posted by Braun on December 1, 2011

I want to build a state machine.
Task 1 and Task 2 start and will be processed.
Once these have been processed Task3 should be executed.
Then everything will repeat itself.
The tasks are executed only once.

//global Variable

xTaskCreate( vZustandmanager, "Zustandmanager", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
void vZustandmanager( void *pvParameters )

switch (state)
case 0:
xTaskCreate( vTask10, "Task 10", configMINIMAL_STACK_SIZE, NULL, 2, &xTask10Handle );
case 1:
xTaskCreate( vTask12, "Task 12", configMINIMAL_STACK_SIZE, NULL, 2, &xTask12Handle );
void vTask10( void *pvParameters )

timer1Interrupt = 0; //volatile
set_timer1(3417); //250ms
while(timer1Interrupt == 0);//OF Bit Interrupt
taskdelete++; //global variable
vTaskDelete( &xTask10Handle );
void vTask12( void *pvParameters )

vTaskDelete( xTask12Handle );

RE: Delete Tasks

Posted by Owen on December 2, 2011
I suppose one of these lines is incorrect:

vTaskDelete( &xTask10Handle );
vTaskDelete( xTask12Handle );


RE: Delete Tasks

Posted by Richard Damon on December 2, 2011
First a comment on design, do NOT just wildly create and delete tasks, this is almost always a wrong solution.

One big problem I see with your code is your Zustandmanager task continually runs creating tasks. It may get held for a moment as the tasks that it creates run, but it will never give up the processor for the idle task, and that means that the tasks that are deleted are never cleaned up from, so you WILL run out of memory.

Second, if your goal is for tasks 1 & 2 to run, and when they finish for task 3 to run, and when it finishes tasks 1&2 to run again and so on, then none of these tasks should be deleted, but should just wait on semaphores to tell them when to go, and then as tasks finish they set the appropriate semaphore to tell the next task to go.

[ 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