Multi Threading, blockingqueue

Hi,

I would like to know if some BlockingQueue equivalent exists in unreal engine ?

If not could i implement it my self using the equivalent of std::condition_variable and mutex ?

I have red that FPThreadsCriticalSection could be used as mutex but how could i use condition_variable ?

If i want to use the std library, I just have to put the std:: prefix, should I change something in the project configuration too ?

I have foud this tutorial on multi-threading:
https://wiki.unrealengine.com/Multi-Threading:_How_to_Create_Threads_in_UE4

I don’t understand what is



AVictoryGamePlayerController* ThePC;
ThePC->ClientMessage(FString::FromInt(PrimeNumbers->Last()));


in his main thread
he used



FPrimeNumberWorker::JoyInit(PrimeNumbers, 50000, this);


I understand that “this” is a reference to the main thread but in which class can i call this method ?
Where do my unreal project start ? in ProjectGameMode.cpp ?

Last question Can I change the attribute of an AActor in an oher Thread than the GameThread ?

That’s a lot of question, sorry

Okay, I know that the topic was created 3 years ago. However, I am studying multithreading at the moment and I think it will be useful for everyone else. Since such examples with full implementation on the Internet, I did not find. You just have to dig into the engine code.

You can start your stream, for example, from the BeginPlay method (do not forget to add it to the header file if you don’t have one)


void APayerControlThread::BeginPlay()
{
    Super::BeginPlay();

    FPrimeNumberWorker::JoyInit(PrimeNumbers, 50000, this);
}

And also do not forget to add stream tearing to EndPlay. In my case, until the thread stopped calculating - I just could not finish the game process, otherwise the engine crashed


void APayerControlThread::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
    FPrimeNumberWorker::Shutdown();

    Super::EndPlay(EndPlayReason);
}

I forgot to say that all this should be in the PlayerController, as Rama pointed out in his post

Look up thread fencing and render fencing in UE4. It’s similar to using a thread dispatcher and then waiting for all the threads to report back when they’re done. You will block on stepping to the next line of code in the sequence until the fence completes.