Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


about Task and Classical Function

Posted by fabrice48 on May 30, 2014

i began with freertos, and read two times the tutorial book, very nicely written and interessting.

i'm not sure about on thingn perhaps my question will be strange for RTOS Guru but i need to understand :

in freertos, all is a task. But in 'C' language we have function.

in a CORRECT FREERTOS programm, is ALL a TASK or i can declare classical C function and call them from a TASK. About function i mean a function without infinite loop, just a function who do something then terminate and return 'to the caller' here, a task for example ????

about Task and Classical Function

Posted by davedoors on May 30, 2014

A function that implements a task can't return to its caller, because there is no caller. If you want to end a task you simply call vTaskDelete(NULL) at the end of the function.

But inside the task you can call normal C functions that return without any problems. Example

void vThisIsATask(void *px)
    // Normal C functions can be called here.

  // Must not exit, but if you leave the while(1) you can delete the task

about Task and Classical Function

Posted by fabrice48 on May 30, 2014

ok, it's more clear for me, can i ask you an advice :

in your experience end opinion how can i choose between a C function and a C function that is a task. i mean what "kind" of code muste be on the one but never to the other ?

about Task and Classical Function

Posted by richard_damon on May 30, 2014

A function that returns will never be a "task".

A function that never returns will rarely be anything but a task function.

A task will generally be in a loop, blocking on some resource, and when it get it, does some operation, and then normally go back and waits for the next request from that resource, or sometimes just terminating itself (if it was created as a "one shot" operation)

One the other hand, a function gets called, does something and then returns to the caller.

It is possible to fake something like a function with a task by sending it a request, and then immediately waiting for a reply. But this is generally inefficient.

Normally I create a task for each data stream from somewhere that needs to be processed, plus tasks for any periodic operations that might take some time to execute (quick periodic operations will become timer callbacks, that run as part of the time task).

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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner