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

new task after vTaskStartScheduler

Posted by Marius Cirsta on April 28, 2010
I'm looking to dynamically create and delete tasks after vTaskStartScheduler was called ( a sort of thread pool ).

I've tried using a function pointer for a task defined before calling vTaskStartScheduler and then modifying the pointer at some point but that didn't work , it still ran the old function defined when the task was created.

I've also tried deleting a running task which worked but then creating a new one with xTaskCreate failed. I'm thinking that xTaskCreate won't work after vTaskStartScheduler was called.

Is there any way to add new tasks after vTaskStartScheduler was called ?

Thank you.

RE: new task after vTaskStartScheduler

Posted by Richard on April 28, 2010
There should be no reason why you cannot create and delete tasks after the scheduler has been started using the normal API functions. Creating a task will fail if there is insufficient heap space for the task stack. You can use xPortGetFreeHeapSize() to check how much stack is free.

To delete tasks you must ensure the memory the kernel allocated to the task can be freed. This means that the idle task must not be starved of processing time, and you cannot use heap_1.c.

Regards.

RE: new task after vTaskStartScheduler

Posted by Marius Cirsta on April 29, 2010
Thanks for your answer , I'll investigate this problem further.

RE: new task after vTaskStartScheduler

Posted by Marius Cirsta on April 29, 2010
I've checked and it seems the problem was indeed that there was not enough memory available for starting another task. Also deleting the task didn't free up any memory because as you said the memory allocation was implemented using heap_1.c

Isn't it possible in any way to divert a task to do something else without deleting it and creating another one. I'm guessing using a function pointer instead of a function name when starting a task won't work ?

RE: new task after vTaskStartScheduler

Posted by Richard Damon on April 29, 2010
Once a task has started, trying to do something outside that task to redirect it elsewhere is a very bad idea, as you have practically no idea where the task currently is.

Note that when you give the create task call a function name, that name IS passed to the create function as a function pointer. Changing it afterward won't change what the task is doing, as that value is just used as where to start.

If you want a task to do different things, then what you need to do is have the task in part of its loop query what it is being asked to do and then go off and do that task, and when it checks again later maybe it does something else.

The big question comes, why do do want to change on the fly what a task does?

RE: new task after vTaskStartScheduler

Posted by Marius Cirsta on April 30, 2010
Yes , you are right , the best way would be to check for something in the task loop.

As to why I would want such a thing , it's because I want to implement a sort of thread pool concept. There are 2 fixed tasks that do the same thing and 2 tasks that can be assigned to various other tasks and then when that task is finished be used for something else.

Thank you all for your support , it helped .


[ 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