add concurrency join check for debug pthread_join failed issue

This commit is contained in:
obdev
2023-02-24 12:20:29 +00:00
committed by ob-robot
parent 022cf12f51
commit 1ce0caed61
2 changed files with 9 additions and 1 deletions

View File

@ -56,7 +56,8 @@ Thread::Thread(Runnable runnable, int64_t stack_size)
stack_addr_(nullptr),
#endif
stack_size_(stack_size),
stop_(true)
stop_(true),
join_concurrency_(0)
{}
Thread::~Thread()
@ -170,6 +171,9 @@ void Thread::wait()
{
int ret = OB_SUCCESS;
if (pth_ != 0) {
if (2 <= ATOMIC_AAF(&join_concurrency_, 1)) {
abort();
}
if (OB_FAIL(pthread_join(pth_, nullptr))) {
LOG_ERROR("pthread_join failed", K(ret), K(errno));
#ifndef OB_USE_ASAN
@ -182,6 +186,9 @@ void Thread::wait()
pid_ = 0;
tid_ = 0;
runnable_ = nullptr;
if (1 <= ATOMIC_AAF(&join_concurrency_, -1)) {
abort();
}
}
}

View File

@ -65,6 +65,7 @@ private:
#endif
int64_t stack_size_;
bool stop_;
int64_t join_concurrency_;
};
OB_INLINE pid_t Thread::get_pid() const