ZEPHYR MALLOC/FREE are not thread safe
ZEPHYR implementation of MALLOC/free relies on NEWLIB rather than on ZEPHYR k_malloc
. THe NEWLIB functions cannot be thread safe.
Change implementation to protect accesses:
- add mutex
- or remove dependancy to NEWLIB and use k_malloc / k_free
Warnings for MBEDTLS:
-
MBEDTLS_PLATFORM_MEMORY
,MBEDTLS_THREADING_C
,MBEDTLS_THREADING_ALT
must be defined -
MBEDTLS_MEMORY_BUFFER_ALLOC_C
must be added -
mbedtls_threading_set_alt
shall be called beforembedtls_memory_buffer_alloc_init
Furthermore: remove instrumentation that can be natively checked in Zephyr shell:
CONFIG_INIT_STACKS=y
CONFIG_THREAD_STACK_INFO=y
CONFIG_THREAD_MONITOR=y
CONFIG_THREAD_RUNTIME_STATS=y
CONFIG_SCHED_THREAD_USAGE_ANALYSIS=y
Note : Same question on WINDOWS, it seems that malloc is not thread safe by default (may depend on compile options)
See also #1204 (closed)
Edited by Jérémie Chabod