Merge branch 'fix_thread_join' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-fix_thread_join
This commit is contained in:
@@ -55,8 +55,7 @@ LoadingThread::~LoadingThread()
|
|||||||
// Check if has thread attached
|
// Check if has thread attached
|
||||||
if (_thread != nullptr)
|
if (_thread != nullptr)
|
||||||
{
|
{
|
||||||
if (_thread->IsRunning())
|
_thread->Kill(true);
|
||||||
_thread->Kill(true);
|
|
||||||
Delete(_thread);
|
Delete(_thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ void ThreadBase::SetPriority(ThreadPriority priority)
|
|||||||
void ThreadBase::Kill(bool waitForJoin)
|
void ThreadBase::Kill(bool waitForJoin)
|
||||||
{
|
{
|
||||||
if (!_isRunning)
|
if (!_isRunning)
|
||||||
|
{
|
||||||
|
ClearHandleInternal();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
ASSERT(GetID());
|
ASSERT(GetID());
|
||||||
const auto thread = static_cast<Thread*>(this);
|
const auto thread = static_cast<Thread*>(this);
|
||||||
|
|
||||||
@@ -105,7 +108,6 @@ int32 ThreadBase::Run()
|
|||||||
_callAfterWork = false;
|
_callAfterWork = false;
|
||||||
_runnable->AfterWork(false);
|
_runnable->AfterWork(false);
|
||||||
}
|
}
|
||||||
ClearHandleInternal();
|
|
||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
ThreadExiting(thread, exitCode);
|
ThreadExiting(thread, exitCode);
|
||||||
ThreadRegistry::Remove(thread);
|
ThreadRegistry::Remove(thread);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ UnixThread* UnixThread::Setup(UnixThread* thread, uint32 stackSize)
|
|||||||
void UnixThread::Join()
|
void UnixThread::Join()
|
||||||
{
|
{
|
||||||
pthread_join(_thread, nullptr);
|
pthread_join(_thread, nullptr);
|
||||||
|
ClearHandleInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnixThread::ClearHandleInternal()
|
void UnixThread::ClearHandleInternal()
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ unsigned long Win32Thread::ThreadProc(void* pThis)
|
|||||||
void Win32Thread::Join()
|
void Win32Thread::Join()
|
||||||
{
|
{
|
||||||
WaitForSingleObject((HANDLE)_thread, INFINITE);
|
WaitForSingleObject((HANDLE)_thread, INFINITE);
|
||||||
|
ClearHandleInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Thread::ClearHandleInternal()
|
void Win32Thread::ClearHandleInternal()
|
||||||
|
|||||||
@@ -149,8 +149,7 @@ void JobSystemService::Dispose()
|
|||||||
{
|
{
|
||||||
if (Threads[i])
|
if (Threads[i])
|
||||||
{
|
{
|
||||||
if (Threads[i]->IsRunning())
|
Threads[i]->Kill(true);
|
||||||
Threads[i]->Kill(true);
|
|
||||||
Delete(Threads[i]);
|
Delete(Threads[i]);
|
||||||
Threads[i] = nullptr;
|
Threads[i] = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,10 +98,7 @@ void ThreadPoolService::Dispose()
|
|||||||
// Delete threads
|
// Delete threads
|
||||||
for (int32 i = 0; i < ThreadPoolImpl::Threads.Count(); i++)
|
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();
|
ThreadPoolImpl::Threads.ClearDelete();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user