Quality RTOS & Embedded Software

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




Loading

Why malloc and free can cause problem in freeRTOS?

Posted by bou6 on August 27, 2016

I read that freeRTOS provide the two functions vPortFree and vPortmalloc as an alternative to malloc and free of glibc, however according to this reference http://stackoverflow.com/questions/855763/is-malloc-thread-safe malloc and free are thread safe. So my question is why freeRTOS provide this alternative and what can happen if i call malloc and free


Why malloc and free can cause problem in freeRTOS?

Posted by richard_damon on August 27, 2016

Note, that answer says it is thread safe when you compile with -pthreads. That is an option used for POSIX systems, i.e with full blown operating systems.

Some embeded libraries have hooks that let you make them thread safe, but typically you need to implement those for your RTOS. I beleive FreeRTOS has available hooks to work with newlib, which is a common library for some enviroments. Basic FreeRTOS can't assume that this is in use, as not systems use this. (There could be a variant of heap3 that does assume newlib and the RTOS hooks are being used that just calls malloc and free).


Why malloc and free can cause problem in freeRTOS?

Posted by richard_damon on August 27, 2016

The other thing, you need to be a bit careful about using C/C++ answers on a forum like that, as many people will just assume they are talking about a full hosted enviroment (with a full operating system like Windows or Linux or the like) and that may not be always applicable to small systems.


Why malloc and free can cause problem in freeRTOS?

Posted by rtel on August 28, 2016

See http://www.freertos.org/a00111.html In my opinion it is very rare that malloc() and free() are suitable for very small real time systems, unless they are provided by a specialist company, such as IAR (and even then perhaps not, depending on what your particular application is actually needing).


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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