apache / brpc

brpc is an Industrial-grade RPC framework using C++ Language, which is often used in high performance system such as Search, Storage, Machine learning, Advertisement, Recommendation etc. "brpc" means "better RPC".
https://brpc.apache.org
Apache License 2.0
16.56k stars 3.98k forks source link

Support detection of mutex deadlock caused by double lock #2765

Closed chenBright closed 1 month ago

chenBright commented 2 months ago

What problem does this PR solve?

Issue Number:

Problem Summary:

What is changed and the side effects?

Changed:

加锁成功记录下拥有锁的bthread/pthread id,如果在同一个bthread/pthread,就可以检测到在同一个bthread/pthread中重复加锁。

Side effects:


Check List:

wwbmmm commented 2 months ago

这个是否会影响性能?

chenBright commented 2 months ago

这个是否会影响性能?

之前的实现不会影响性能,但是没用原子变量没法保证正确性。现在用原子变量实现后会导致性能退化,MutexTest.performance测试发现锁的平均运行时间慢了50%左右,所以该功能只作为debug手段,默认关闭,只有编译bRPC库时定义了DEBUG_MUTEX宏才会开启该功能。

wwbmmm commented 2 months ago

LGTM

wwbmmm commented 1 month ago

@chenBright 这个PR和主干冲突了

chenBright commented 1 month ago
  1. rebase解决冲突。
  2. 支持pthread mutex。