how to use newlib multi thread safety ?

横眉冷对秋波 370615657@qq.com
Tue Jun 11 11:05:21 GMT 2024


Sorry to bother you, the maintainer of the newlib library. Our project currently uses Cortex-M55 CPU and also uses the newlib library and FreeRTOS. The cross compilation toolchain uses the arm_gnu_toolchain-13.2. Rel1-x86_64_arm_none_eabi version.  
I have a few questions to consult:
1. We configured configUSE-NEWLIB-REENTRANT=1 in FreeRTOS and implemented the following two interfaces:
Void _malloc'lock (struct reent * reent)
Void _malloc_unlock (struct reent * reent)
In this case, is using all interfaces of the newlib library multi-threaded safe? For example, are interfaces such as fopen, fread, fwrite, etc. multithreading safe? 
Of course, the newlib library provides some interfaces that end in '_r' and we will also use them? Can this cover all interface threads safely?


2. From the official website of newlib, it can be seen that the following interfaces also need to be implemented:
#Include<lock. h>
struct __lock __lock___sinit_recursive_mutex;
struct __lock __lock___sfp_recursive_mutex;
struct __lock __lock___atexit_recursive_mutex;
struct __lock __lock___at_quick_exit_mutex;
struct __lock __lock___malloc_recursive_mutex;
struct __lock __lock___env_recursive_mutex;
struct __lock __lock___tz_mutex;
struct __lock __lock___dd_hash_mutex;
struct __lock __lock___arc4random_mutex;
Void __ retarget lock init (LOCK_ T * lock ptr);
Void __ retarget lock init recursive (LOCK_ T * lock ptr);
Void __ retarget lock close (LOCK_ T lock);
Void __ retarget lock close recursive (LOCK_ T lock);
Void __ retarget lock acquire (LOCK_ T lock);
Void __ retarget lock acquire recursive (LOCK_ T lock);
Int __ retarget lock try acquire (LOCK_ T lock);
Int __ retarget lock try acquire recursive (LOCK_ T lock);
Void __ retarget lock release (LOCK_ T lock);
Void __ retarget lock release recursive (LOCK_ T lock);


Can implementing only these interfaces ensure the safety of multithreading, or must configUSE-NEWLIB-REENTRANT=1 be configured simultaneously, and both hook functions of malloc must be implemented, while also implementing all interfaces in 2?
Thank you very much for your answer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20240611/4c468f68/attachment.htm>


More information about the Newlib mailing list