We're experiencing what appears to be an issue with concurrent dynamic allocations of memory in a multithreaded Synergy C++ project using the newlib distributed with the arm-none-eabi GCC 7.2.1 2017Q4 toolchain (not newlib-nano).
During our most active point of execution, we have a number of control loops running in parallel, as well as a thread that is publishing recorded data from those control loops. The published data is allocated dynamically and shared between threads via shared memory and protected with ThreadX mutexes. Data is deallocated (via managed RAII scoping) following the publish.
After varying time periods of execution we are experiencing failures that end up in the default handler. The stack traces reveal in most instances that at the point of failure that multiple threads (including the one that indicates the fault) are in the _free_r_ function from the newlib libc. The _r_ suffix indicates that this is the reentrant version of this deallocation.
While I know that reentrant != thread safe, the ISO C++ standard (starting with C++11) requires that new and delete are thread safe operators. Reducing dynamic allocations in code pieces known to be heavily parallelized improves stability of the application, but this raises a great deal of concerns of the viability of our SW's architecture.
It is of course possible that this is a red herring, it raises a number of questions:
Is it possible that the versions of libc++ and newlib libc shipped with this toolchain is not ISO compliant?
How do I determine the version of the library?
Is there potentially a linker option that is being missed?The current linker options are as follows and the script has not been significantly modified:
-T "C:\\jobs\\repos\\sw_emb_product\\projects\\e2_studio\\product\\script\\s5d9.ld" -Xlinker --gc-sections -L "C:\\jobs\\repos\\sw_emb_product\\projects\\e2_studio\\library_synergy_devkit\\Debug" -L "C:\\jobs\\repos\\sw_emb_product\\projects\\e2_studio\\library_synergy_devkit\\synergy\\ssp\\src\\bsp\\cmsis\\DSP_Lib\\cm4_gcc" -L "C:\\jobs\\repos\\sw_emb_product\\projects\\e2_studio\\library_synergy_devkit\\synergy\\ssp\\src\\framework\\el\\tx\\cm4_gcc" -L "C:\\jobs\\repos\\sw_emb_product\\projects\\e2_studio\\library_synergy_devkit\\synergy\\ssp\\src\\framework\\el\\nxd\\cm4_gcc" -L "C:\\jobs\\repos\\sw_emb_product\\projects\\e2_studio\\library_synergy_devkit\\synergy\\ssp\\src\\driver\\r_sce\\libs" -Wl,-Map,"product.map" -u _printf_float -u _scanf_float --specs=rdimon.specs -Wl,--whole-archive -llibrary_synergy_devkit -Wl,--no-whole-archive
Thank you in advance for the great support!