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

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) 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