FreeRTOS / Lab-Project-FreeRTOS-POSIX

This repository contains FreeRTOS+POSIX source code, which could be consumed as a submodule.
MIT License
95 stars 60 forks source link

How to use with configSUPPORT_DYNAMIC_ALLOCATION = 0 ? #21

Closed begriffs closed 1 year ago

begriffs commented 1 year ago

Hi, this comment says that FreeRTOS+Posix uses only static memory allocation. However, I didn't succeed in using the project with the following settings in FreeRTOSConfig.h:

#define configSUPPORT_DYNAMIC_ALLOCATION 0
#define configSUPPORT_STATIC_ALLOCATION  1

The failure happened because pthread_create uses pvPortMalloc here: https://github.com/FreeRTOS/Lab-Project-FreeRTOS-POSIX/blob/3b33c3467d1345d332752aa9c155da9683183c49/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c#L295

Is there an alternative function to pthread_create I should use in projects without dynamic allocation support?

dachalco commented 1 year ago

Hi @begriffs

Currently there is no such logic in our +POSIX library that switches between only static or only dynamic memory use. I'm not sure there's a POSIX mechanism to specify that either. You must support dynamic allocation with this library as pvPortMalloc is used both directly in pthread_create and within it's usage of xTaskCreate.

You can entirely avoid dynamic allocation by directly using kernel functions. xTaskCreateStatic enables you to statically allocate thread's kernel resources. It needs to be enabled with configSUPPORT_STATIC_ALLOCATION == 1.

n9wxu commented 1 year ago

Sadly the original comment is incorrect. FreeRTOS+Posix only supports dynamic memory.