-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
newlib: add thread safe implementation #8619
Conversation
The main problem with #4529 sticks however (for later reference 78c4080 was the initial commit in this PR):
And that's just the minimal application (i.e. main+idle threads). |
How about adding a thread flag that controls allocation of a thread local reent struct? |
Only +85 lines, nice! |
Yeah, this seems expensive. OTOH, currently, it is just plain luck that we're not seeing more problems due to not thread-safe newllib calls... |
This can not really be solved I guess... A |
Fixed typo. Just to add another argument: this code could still be disabled by default if there is no consensus, it's simply a module ( |
Re-added (and hopefully improved) the |
See OTAkeys#10 for an example of per-thread control of reent struct allocation |
How do we want to proceed here? @kaspar030 @miri64 what is your feeling here? |
ping @kaspar030 @miri64 |
@vincent-d Once this gets merged, should I modify the tlsf malloc to use |
I don't think so,
I thought the checks in |
So if the entire malloc/free/etc family of functions is replaced, then I don't have to worry about newlib locks?
Yes, they are good! What is not good is what is currently in the tree (it does not perform enough checks). |
Coming back on this, I really think we should have this feature.
They are also used internally from printf/scanf functions if I understand correctly. |
@vincent-d One thing I don't fully understand: right now, is it safe to call memory allocation functions from more than one thread? If the answer is no, then this feature is not optional, it's required. |
I believe it's not. One can easily reproduce printing issue with multiple threads, and I didn't need a lot pf research to find this kind of articles: http://www.nadler.com/embedded/newlibAndFreeRTOS.html among others. |
d05c147
to
3d2318d
Compare
Can we try to reach a consensus here? @kaspar030 @gebart @haukepetersen is there any reason to block this as-is? Btw, rebased! |
@vincent-d I'd like this to be merged. Even more, I'd want it to be the default (but that could be done in another PR.) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
2a31cbf
to
8b43d5b
Compare
Rebased. |
@vincent-d Have you come across any platform where newlib-nano does not have reent support? Maybe we can devise some script that iterates through all platforms and checks this. Then we can say "only reent newlib" is supported and remove the ifdefs. If we don't guarantee reentrancy then its value is greatly diminished as we cannot write portable code that relies on this. |
@vincent-d I'm sorry to join the discussion so late. I didn't know about this PR before.
For some platforms, e.g.. Cortex-M, RISC-V or ESP, all these lock functions are simply mapped by the newlib to the functions [UPDATE] It seems that RIOT uses the newlib-nano for Cortex-M and RISC-V for which the statements above aren't true 😎 So IMHO, it would be a more general approach for platforms that use the newlib instead of the newlib-nano to implement the For the ESP platforms, I had already implemented these |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
@kaspar030 @miri64 @gschorcht - any path to progress this? |
Should be superseded by #15606 |
Contribution description
Inspired by #4529, but using
rmutex
, this implements__malloc_lock
/__malloc_unlock
and__env_lock
/__env_unlock
syscalls to make newlib trhead-safe.I guess it should be improved to check whether
_REENT_SMALL
is defined, and maybe disabled by default...Issues/PRs references
#4529, fixes #4488