backup pid && tid of pthread before stop

This commit is contained in:
obdev
2023-03-15 07:11:01 +00:00
committed by ob-robot
parent f5057f146f
commit cb4c4572e6
2 changed files with 16 additions and 1 deletions

View File

@ -58,7 +58,9 @@ Thread::Thread(Runnable runnable, int64_t stack_size)
#endif
stack_size_(stack_size),
stop_(true),
join_concurrency_(0)
join_concurrency_(0),
pid_before_stop_(0),
tid_before_stop_(0)
{}
Thread::~Thread()
@ -127,6 +129,17 @@ int Thread::start(Runnable runnable)
void Thread::stop()
{
#ifndef OB_USE_ASAN
if (!stop_ && stack_addr_ != NULL) {
int tid_offset = 720;
int pid_offset = 724;
int len = (char*)stack_addr_ + stack_size_ - (char*)pth_;
if (len >= (max(tid_offset, pid_offset) + sizeof(pid_t))) {
tid_before_stop_ = *(pid_t*)((char*)pth_ + tid_offset);
pid_before_stop_ = *(pid_t*)((char*)pth_ + pid_offset);
}
}
#endif
stop_ = true;
}

View File

@ -81,6 +81,8 @@ private:
int64_t stack_size_;
bool stop_;
int64_t join_concurrency_;
pid_t pid_before_stop_;
pid_t tid_before_stop_;
};
OB_INLINE pid_t Thread::get_pid() const