Support pthread mutex deadlock detection #2692
Merged
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.
What problem does this PR solve?
Issue Number:
Problem Summary:
线程锁临界区内挂起协程(bthread_mutex、sync rpc、bthread_usleep、bthread_yield等),属于未定义行为(大概率会造成死锁)。目前缺少一种发现机制,只能等到出现死锁后查看调用栈再排查。
What is changed and the side effects?
Changed:
brpc已经hook了pthread mutex接口,加锁的时候将线程局部变量加一,解锁的时候,将线程局部变量减一。只有在线程局部变量等于0的时候,挂起协程才是安全的,否则,将调用栈打印出来用于排查问题。该调用栈只打印一次,因为一旦出现pthread mutex临界区内挂起协程,线程局部变量已经是错乱的,后续的调用栈已经没有参考价值。
Side effects:
Performance effects(性能影响):
Breaking backward compatibility(向后兼容性):
Check List: