This is an automated email from the ASF dual-hosted git repository.
guangmingchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 1152b80e Use SetNameSimple instead of SetName to avoid deadlock (#3127)
1152b80e is described below
commit 1152b80e5fcf8c9d6fe9047dff46539a60c8c4b3
Author: Bright Chen <[email protected]>
AuthorDate: Mon Oct 27 21:00:07 2025 +0800
Use SetNameSimple instead of SetName to avoid deadlock (#3127)
---
src/brpc/details/usercode_backup_pool.cpp | 2 +-
src/bthread/execution_queue.cpp | 2 +-
src/bthread/task_control.cpp | 2 +-
src/bthread/timer_thread.cpp | 2 +-
src/butil/threading/platform_thread.h | 1 +
src/butil/threading/platform_thread_freebsd.cc | 5 +++++
src/butil/threading/platform_thread_linux.cc | 4 ++++
src/butil/threading/platform_thread_mac.mm | 5 +++++
src/bvar/collector.cpp | 4 ++--
src/bvar/detail/sampler.cpp | 2 +-
src/bvar/variable.cpp | 2 +-
11 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/brpc/details/usercode_backup_pool.cpp
b/src/brpc/details/usercode_backup_pool.cpp
index 489def45..338038ae 100644
--- a/src/brpc/details/usercode_backup_pool.cpp
+++ b/src/brpc/details/usercode_backup_pool.cpp
@@ -92,7 +92,7 @@ UserCodeBackupPool::UserCodeBackupPool()
}
static void* UserCodeRunner(void* args) {
- butil::PlatformThread::SetName("brpc_user_code_runner");
+ butil::PlatformThread::SetNameSimple("brpc_user_code_runner");
static_cast<UserCodeBackupPool*>(args)->UserCodeRunningLoop();
return NULL;
}
diff --git a/src/bthread/execution_queue.cpp b/src/bthread/execution_queue.cpp
index 88d96c2b..ae6f97b4 100644
--- a/src/bthread/execution_queue.cpp
+++ b/src/bthread/execution_queue.cpp
@@ -208,7 +208,7 @@ void* ExecutionQueueBase::_execute_tasks(void* arg) {
}
void* ExecutionQueueBase::_execute_tasks_pthread(void* arg) {
- butil::PlatformThread::SetName("ExecutionQueue");
+ butil::PlatformThread::SetNameSimple("ExecutionQueue");
auto head = (TaskNode*)arg;
auto m = (ExecutionQueueBase*)head->q;
m->_current_head = head;
diff --git a/src/bthread/task_control.cpp b/src/bthread/task_control.cpp
index feeeb7d4..e43ce1ec 100644
--- a/src/bthread/task_control.cpp
+++ b/src/bthread/task_control.cpp
@@ -103,7 +103,7 @@ void* TaskControl::worker_thread(void* arg) {
std::string worker_thread_name = butil::string_printf(
"brpc_wkr:%d-%d", g->tag(),
c->_next_worker_id.fetch_add(1, butil::memory_order_relaxed));
- butil::PlatformThread::SetName(worker_thread_name.c_str());
+ butil::PlatformThread::SetNameSimple(worker_thread_name.c_str());
}
BT_VLOG << "Created worker=" << pthread_self() << " tid=" << g->_tid
<< " bthread=" << g->main_tid() << " tag=" << g->tag();
diff --git a/src/bthread/timer_thread.cpp b/src/bthread/timer_thread.cpp
index bd1f4870..813104a4 100644
--- a/src/bthread/timer_thread.cpp
+++ b/src/bthread/timer_thread.cpp
@@ -121,7 +121,7 @@ inline bool task_greater(const TimerThread::Task* a, const
TimerThread::Task* b)
}
void* TimerThread::run_this(void* arg) {
- butil::PlatformThread::SetName("brpc_timer");
+ butil::PlatformThread::SetNameSimple("brpc_timer");
static_cast<TimerThread*>(arg)->run();
return NULL;
}
diff --git a/src/butil/threading/platform_thread.h
b/src/butil/threading/platform_thread.h
index 8a1937a4..fb36d451 100644
--- a/src/butil/threading/platform_thread.h
+++ b/src/butil/threading/platform_thread.h
@@ -154,6 +154,7 @@ class BUTIL_EXPORT PlatformThread {
// otherwise. This name pointer is not copied internally. Thus, it must stay
// valid until the thread ends.
static void SetName(const char* name);
+ static void SetNameSimple(const char* name);
// Gets the thread name, if previously set by SetName.
static const char* GetName();
diff --git a/src/butil/threading/platform_thread_freebsd.cc
b/src/butil/threading/platform_thread_freebsd.cc
index 40e15d1e..a18264be 100644
--- a/src/butil/threading/platform_thread_freebsd.cc
+++ b/src/butil/threading/platform_thread_freebsd.cc
@@ -48,6 +48,11 @@ void PlatformThread::SetName(const char* name) {
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
tracked_objects::ThreadData::InitializeThreadContext(name);
+ SetNameSimple(name);
+}
+
+// static
+void PlatformThread::SetNameSimple(const char* name) {
#if !defined(OS_NACL)
// On FreeBSD we can get the thread names to show up in the debugger by
// setting the process name for the LWP. We don't want to do this for the
diff --git a/src/butil/threading/platform_thread_linux.cc
b/src/butil/threading/platform_thread_linux.cc
index 274e9a8b..7a705604 100644
--- a/src/butil/threading/platform_thread_linux.cc
+++ b/src/butil/threading/platform_thread_linux.cc
@@ -54,6 +54,10 @@ int ThreadNiceValue(ThreadPriority priority) {
void PlatformThread::SetName(const char* name) {
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
+ SetNameSimple(name);
+}
+// static
+void PlatformThread::SetNameSimple(const char* name) {
#if !defined(OS_NACL)
// On linux we can get the thread names to show up in the debugger by setting
// the process name for the LWP. We don't want to do this for the main
diff --git a/src/butil/threading/platform_thread_mac.mm
b/src/butil/threading/platform_thread_mac.mm
index 22913012..a9f74f48 100644
--- a/src/butil/threading/platform_thread_mac.mm
+++ b/src/butil/threading/platform_thread_mac.mm
@@ -46,6 +46,11 @@ void PlatformThread::SetName(const char* name) {
// TODO: add tracked_objects related headers
//tracked_objects::ThreadData::InitializeThreadContext(name);
+ SetNameSimple(name);
+}
+
+// static
+void PlatformThread::SetNameSimple(const char* name) {
// Mac OS X does not expose the length limit of the name, so
// hardcode it.
const int kMaxNameLength = 63;
diff --git a/src/bvar/collector.cpp b/src/bvar/collector.cpp
index d708bd52..34713a4a 100644
--- a/src/bvar/collector.cpp
+++ b/src/bvar/collector.cpp
@@ -77,13 +77,13 @@ private:
int64_t interval_us);
static void* run_grab_thread(void* arg) {
- butil::PlatformThread::SetName("bvar_collector_grabber");
+ butil::PlatformThread::SetNameSimple("bvar_collector_grabber");
static_cast<Collector*>(arg)->grab_thread();
return NULL;
}
static void* run_dump_thread(void* arg) {
- butil::PlatformThread::SetName("bvar_collector_dumper");
+ butil::PlatformThread::SetNameSimple("bvar_collector_dumper");
static_cast<Collector*>(arg)->dump_thread();
return NULL;
}
diff --git a/src/bvar/detail/sampler.cpp b/src/bvar/detail/sampler.cpp
index 2e231d22..dd6271e7 100644
--- a/src/bvar/detail/sampler.cpp
+++ b/src/bvar/detail/sampler.cpp
@@ -109,7 +109,7 @@ private:
void run();
static void* sampling_thread(void* arg) {
- butil::PlatformThread::SetName("bvar_sampler");
+ butil::PlatformThread::SetNameSimple("bvar_sampler");
static_cast<SamplerCollector*>(arg)->run();
return NULL;
}
diff --git a/src/bvar/variable.cpp b/src/bvar/variable.cpp
index fe76b347..80c3049e 100644
--- a/src/bvar/variable.cpp
+++ b/src/bvar/variable.cpp
@@ -730,7 +730,7 @@ static GFlag
s_gflag_bvar_dump_interval("bvar_dump_interval");
static void* dumping_thread(void*) {
// NOTE: this variable was declared as static <= r34381, which was
// destructed when program exits and caused coredumps.
- butil::PlatformThread::SetName("bvar_dumper");
+ butil::PlatformThread::SetNameSimple("bvar_dumper");
const std::string command_name = read_command_name();
std::string last_filename;
std::string mbvar_last_filename;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]