fix thread hang when os oom

This commit is contained in:
nroskill
2024-01-05 05:43:05 +00:00
committed by ob-robot
parent 6ef2d82735
commit 080a8aded1

View File

@ -99,14 +99,16 @@ int Thread::start()
if (pret == 0) {
stop_ = false;
pret = pthread_create(&pth_, &attr, __th_start, this);
while (ATOMIC_LOAD(&create_ret_) == OB_NOT_RUNNING) {
sched_yield();
}
if (pret != 0) {
LOG_ERROR("pthread create failed", K(pret), K(errno));
pth_ = 0;
} else if (OB_FAIL(create_ret_)) {
LOG_ERROR("thread create failed", K(create_ret_));
} else {
while (ATOMIC_LOAD(&create_ret_) == OB_NOT_RUNNING) {
sched_yield();
}
if (OB_FAIL(create_ret_)) {
LOG_ERROR("thread create failed", K(create_ret_));
}
}
}
if (0 != pret) {
@ -346,6 +348,9 @@ void* Thread::__th_start(void *arg)
}
}
}
if (OB_FAIL(ret)) {
ATOMIC_STORE(&th->create_ret_, ret);
}
ATOMIC_FAA(&total_thread_count_, -1);
return nullptr;
}