From 7fe08a2166ea304ca12c5602c564a72b5d764abe Mon Sep 17 00:00:00 2001 From: Xinyi Zou Date: Fri, 27 Oct 2023 09:43:53 +0800 Subject: [PATCH] 2 --- be/src/runtime/thread_context.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/be/src/runtime/thread_context.h b/be/src/runtime/thread_context.h index 19cb9adabdc1a7..9864137a3bbbc4 100644 --- a/be/src/runtime/thread_context.h +++ b/be/src/runtime/thread_context.h @@ -293,11 +293,15 @@ static ThreadContext* thread_context() { DCHECK(pthread_context_ptr_init); DCHECK(thread_context_ptr != nullptr); return thread_context_ptr; - } else { - // in bthread - DCHECK(bthread_context != nullptr); - return bthread_context; } + // in bthread + if (!bthread_equal(bthread_self(), bthread_id)) { + // bthread switching pthread may be very frequent, remember not to use lock or other time-consuming operations. + bthread_id = bthread_self(); + bthread_context = static_cast(bthread_getspecific(btls_key)); + } + DCHECK(bthread_context != nullptr); + return bthread_context; } class ScopeMemCount {