Are you wanting to block the main thread? That is to say, the game thread? If so, your game will completely freeze until you unblock the Game Thread.
Generally speaking, you would have the Game Thread kick off some work in another thread, with a bound delegate function which will be called automatically on the Game Thread when the work is complete. You achieve this in UE through the FRunnable class. However, if you are looking to simply block the Game Thread, you’ll need to look into the FCriticalSection type, which is UE’s version of a mutex, which is a special type of ‘lock’ used for thread synchronization. It works by blocking all threads that try to access the ‘lock’ while another thread has acquired it.
A really convenient way of using a mutex is through the concept of a Scoped Lock. We use this type of mutex by simply declaring a variable where ever we want to have our lock in effect. The lock will be owned by the thread until the variable goes out of scope.
A simple example:
void GameThread()
{
/*
* Doing some Game Thread stuff..
*/
// Location we want the thread to wait at..
// If we try to take ownership of this lock (Mutex)
// while ThreadTwo has ownership of it, then this
// thread will wait until it is free
FScopeLock ScopedLock(&Mutex);
/*
* Do things after Lock becomes available
*/
}
void ThreadTwo()
{
// Take ownership of the lock to block all other threads
FScopeLock ScopedLock(&Mutex);
/*
* Do protected work
*/
}
Also, an infinite while loop will heavily load the CPU and complete freeze the thread. You should never be implementing infinite while loops unless they contain a sleep. You can sleep threads using the Chrono and Thread libraries in the C++ Standard library. A simple example of that is this:
#include <thread>
#include <chrono>
void SleepFor(const uint32 Milliseconds)
{
std::this_thread::sleep_for(std::chrono::milliseconds(Milliseconds));
}