Quality RTOS & Embedded Software

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


Dynamic allocation of queue creates conflict

Posted by j-md on November 7, 2016

Hi all, I have an application running on Microchip dsPIC33 with FreeRTOS. I use the default options, that is, dynamic allocation everywhere for all FreeRTOS objects. The application has 5 tasks and 3 queues of 20 items of 34 bytes each. The heap_3.c version is used. I came across a bug, where the application would crash when accessing the queues. I eventually found that the 3 queues were created within one of the tasks, and when I looked at the addresses of the queues, they seem to overlap the stack of one of the tasks. I moved the creation of the 3 queues to the main() function, and the problem disappeared. So my question is : how is the dynamic memory allocation handled? Is it forbidden to allocate a queue from within a task?

On another project using a STM32, I currently also have instabilities, and I now realize that one task is creating a recursive mutex. Could this be the same problem again? In any case I will try and create the mutex from the main() function to see if it does any good.

Dynamic allocation of queue creates conflict

Posted by rtel on November 7, 2016

It is very common for tasks to create RTOS objects, and even other tasks. As you are using heap_3 you will be using the malloc() provided by your compiler. My best guess would be that the linker script is not set up correctly for your device.

When you create RTOS objects (Queues, etc.) are you checking the return value of the create function to check the object was actually created before you use it?

If you change the order in which the object are created (by creating the queues before you start the scheduler, as you said in your post) you are not changing the amount of memory allocation, so I expect all you have done is move the problem somewhere else.

Dynamic allocation of queue creates conflict

Posted by j-md on November 7, 2016

Yes, I have checked the return value and if it is null, the processor goes into an endless loop so that I can easily locate the problem in debug mode. In the configuration file, the heap size is set to 15120 which seems to be enough for all the tasks and all the queues. But still, since I moved the queue creation to the main() function, It has worked without any problem. When a task is created, does it allocate the size of the stack ? In my case, I doubted this is true.

Dynamic allocation of queue creates conflict

Posted by davedoors on November 7, 2016

In the configuration file, the heap size is set to 15120

Which configuration file? FreeeRTOSConfig? Heap 3 doesnt use configTOTALHEAPSIZE http://www.freertos.org/a00111.html

[ 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