wwbmmm commented on code in PR #2692:
URL: https://github.com/apache/brpc/pull/2692#discussion_r1677280494


##########
src/bthread/mutex.cpp:
##########
@@ -457,6 +468,24 @@ inline uint64_t hash_mutex_ptr(const Mutex* m) {
 // code are never sampled, otherwise deadlock may occur.
 static __thread bool tls_inside_lock = false;
 
+// ++tls_pthread_lock_count when pthread locking,
+// --tls_pthread_lock_count when pthread unlocking.
+// Only when it is equal to 0, it is safe for the bthread to be scheduled.
+static __thread int tls_pthread_lock_count = 0;
+
+void CheckBthreadScheSafety() {
+    if (BAIDU_LIKELY(0 == tls_pthread_lock_count)) {
+        return;
+    }
+
+    static butil::atomic<bool> b_sched_in_p_lock_logged{false};
+    if (BAIDU_UNLIKELY(!b_sched_in_p_lock_logged.exchange(
+        true, butil::memory_order_relaxed))) {
+        // It can only be checked once because the counter is messed up.
+        CHECK(false) << "bthread is suspended while holding pthread locks";

Review Comment:
   
这里是不是用ERROR级别的日志比较合适?CHECK在某些配置下会直接让程序崩溃,但是有的程序在持有pthread锁时进行bthread切换不一定总会带来死锁,可能还是能正常运行的,加了这个之后就挂了



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to