FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2016 Threads] 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).
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|