Merge branch 'fix_thread_join' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-fix_thread_join

This commit is contained in:
Wojtek Figat
2023-02-15 15:33:44 +01:00
6 changed files with 8 additions and 9 deletions

View File

@@ -55,8 +55,7 @@ LoadingThread::~LoadingThread()
// Check if has thread attached
if (_thread != nullptr)
{
if (_thread->IsRunning())
_thread->Kill(true);
_thread->Kill(true);
Delete(_thread);
}
}

View File

@@ -43,7 +43,10 @@ void ThreadBase::SetPriority(ThreadPriority priority)
void ThreadBase::Kill(bool waitForJoin)
{
if (!_isRunning)
{
ClearHandleInternal();
return;
}
ASSERT(GetID());
const auto thread = static_cast<Thread*>(this);
@@ -105,7 +108,6 @@ int32 ThreadBase::Run()
_callAfterWork = false;
_runnable->AfterWork(false);
}
ClearHandleInternal();
_isRunning = false;
ThreadExiting(thread, exitCode);
ThreadRegistry::Remove(thread);

View File

@@ -53,6 +53,7 @@ UnixThread* UnixThread::Setup(UnixThread* thread, uint32 stackSize)
void UnixThread::Join()
{
pthread_join(_thread, nullptr);
ClearHandleInternal();
}
void UnixThread::ClearHandleInternal()

View File

@@ -113,6 +113,7 @@ unsigned long Win32Thread::ThreadProc(void* pThis)
void Win32Thread::Join()
{
WaitForSingleObject((HANDLE)_thread, INFINITE);
ClearHandleInternal();
}
void Win32Thread::ClearHandleInternal()

View File

@@ -149,8 +149,7 @@ void JobSystemService::Dispose()
{
if (Threads[i])
{
if (Threads[i]->IsRunning())
Threads[i]->Kill(true);
Threads[i]->Kill(true);
Delete(Threads[i]);
Threads[i] = nullptr;
}

View File

@@ -98,10 +98,7 @@ void ThreadPoolService::Dispose()
// Delete threads
for (int32 i = 0; i < ThreadPoolImpl::Threads.Count(); i++)
{
if (ThreadPoolImpl::Threads[i]->IsRunning())
{
ThreadPoolImpl::Threads[i]->Kill(true);
}
ThreadPoolImpl::Threads[i]->Kill(true);
}
ThreadPoolImpl::Threads.ClearDelete();
}