chenBright commented on code in PR #2692:
URL: https://github.com/apache/brpc/pull/2692#discussion_r1677898848
##########
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:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]