oh it was a mistype. I do not kill any class, I kill the running thread using a blueprint node which calls a function in the Frunnable class that calls Kill over FrunnableThread onject.
I will modify the description now. As for the code I can provide it by the evening
I have found out that the problem is with Kill(true). meaning that if I call it Kill(false) then it wouldn’t be a problem.
UE4 freezes due to stuck in WaitForSingleObject(Thread,INFINITE); in the following function
Interestingly there is no problem with debug mode
virtual bool Kill( bool bShouldWait = false ) override
{
check(Thread && "Did you forget to call Create()?");
bool bDidExitOK = true;
// Let the runnable have a chance to stop without brute force killing
if (Runnable)
{
Runnable->Stop();
}
// If waiting was specified, wait the amount of time. If that fails,
// brute force kill that thread. Very bad as that might leak.
if (bShouldWait == true)
{
// Wait indefinitely for the thread to finish. IMPORTANT: It's not safe to just go and
// kill the thread with TerminateThread() as it could have a mutex lock that's shared
// with a thread that's continuing to run, which would cause that other thread to
// dead-lock. (This can manifest itself in code as simple as the synchronization
// object that is used by our logging output classes. Trust us, we've seen it!)
WaitForSingleObject(Thread,INFINITE);
}
// Now clean up the thread handle so we don't leak
CloseHandle(Thread);
Thread = NULL;
return bDidExitOK;
}
I have found the issue, and the solution.
there is no need of the thread to be completed at all. the problem is that since the stop function of the thread is using windows standard functionalities the cpp or at least the part in charge of stopping should be wrapped in #include “AllowWindowsPlatformTypes.h” and #include “HideWindowsPlatformTypes.h”. it will solve the problem.
although your code does not make issue and it is ok the problem is that for your code the thread will and should finish by finishing its work. I might want to have a code which stops the thread on demand. I have posted the solution I have had found for the problem