Resolve the issue of system crashes caused by using mutex locks for memory allocation when a thread polls multiple file descriptors #10592
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…emory allocation when a thread polls multiple file descriptors
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
因为内存分配使用什么锁进行临界区保护很重要,因此对于实时系统如果使用“关中断”或者“禁止调度”这两种措施,对于实时系统是不可接受的,项目中使用这两种临界保护,实时性受到很大影响,特别在堆使用片外sdram时,实时性受影响巨大。所以这两种措施虽然可以解决系统不崩溃问题,但是已经偏离了实时系统的本意。故,只能使用互斥锁,不影响实时线程的调度。但是使用互斥锁的情况下,在某线程使用多fd同时poll时存在致命的bug,系统会死机。早期的rt-thread版本使用的是信号量,同样存在此问题。
你的解决方案是什么 (what is your solution)
对于在某线程使用多个fd同时poll,且内存分配使用互斥类锁时,建议修改poll的机制,不要使用calloc分配node,否则free时会触发bug。
请提供验证的bsp和config (provide the config and bsp)
bsp和config用什么都没问题,系统中最好3个线程以上,线程1最好使用网络,因为这样就有一个监听的fd和一个连接客户端的fd。另外两个线程应存在动态分配内存。
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0
代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up