How to multi thread of wait for new tick?

So I am working on a plugin, and since it has some very heavy tasks I am looking for a way to execute certain functions on another thread then the game thread, because otherwise the performance drop is just to big. These functions don’t have to be completed very fast, so I can afford to lose a bit of speed in these functions. The problem is that I can’t find any good tutorials on multithreading, I have read some things about FRunnable and FRunnaleThread, but I don’t fully understand it.
What also could be a solution, is allowing these functions to be partially executed when they tick, and then one or more ticks after it continue and finnish is, but I don’t know if it is possible and I would like to multhithread it.

Do you know anything about this or know a good tutorial, please help me.

Here is a tutorial from Rama on how to use multithreading in UE4:

Dartanlla, I have found that tutorial already, but I don’t know if I can implement it in my system, this piece of pseudo code should give a better idea of what I want:

.h

class X : Actor
{
//variables for functions
//custom struct with a function inside
//array
void update(); //checks if I want to load or generate
void Generate(); //Sets up variables for generation; Calls GenOneSide twice
void GenOneSide(float PlusX, float PlusY); //Generates one side
//GenOneSide is very heavy, and I want that function to be on a seperate thread, or let it wait for a new tick at certain points
};

How do I let the GenOneSide function run on another thread? It will need some variables that are in class X, but of course I can change things around.

Thanks in advance

I have come a lot further (I think) but now I still crash when trying to execute a certain bit of code on the game thread. As I describe in this post: How to execute code on game thread, using AsyncTask or something like that? - C++ - Epic Developer Community Forums

Okay I got that to work, only one strange thing is still happening:

	AsyncTask(ENamedThreads::GameThread, [=]()
	{
		Debug(Vector1, Vector2, Delta); //Detla = 650.000183
	});
	k = 0;
	UE_LOG(LogTemp, Warning, TEXT("Delta = %f"), Delta); //Delta = -431602080.000000
	UE_LOG(LogTemp, Warning, TEXT("k = %f"), k); //k = 0
	for (k; k < Delta; k++)
	{
//Not executed
		UE_LOG(LogTemp, Warning, TEXT("k = %f"), k);
		UE_LOG(LogTemp, Warning, TEXT("Entered for loop k!"));
	}
	for (int i = 0; i < Delta; i += 50)
	{

``//Not executed
UE_LOG(LogTemp, Warning, TEXT(“Entered for loop i!”));
FHitOut Hit;
Hit.Trace(Vector1, Vector2, This);

		Vector1.Y += PlusX;
		Vector1.X -= PlusY;
		Vector2.Y += PlusX;
		Vector2.X -= PlusY;
		AsyncTask(ENamedThreads::GameThread, [=]()
		{
			Debug(Vector1, Vector2, Delta);
		});

//…

void GenerateCoversThread::Debug(FVector VectorA, FVector VectorB, float DeltaA)
{
	UE_LOG(LogTemp, Warning, TEXT("Debuging"));
	UE_LOG(LogTemp, Warning, TEXT("Delta: %f"), DeltaA)
	DrawDebugSphere(This->GetWorld(), VectorA, 25.f, 12, FColor::Red, false, 5.f, 0, 1.f);
	DrawDebugSphere(This->GetWorld(), VectorB, 25.f, 12, FColor::Red , false, 5.f, 0, 1.f);
	return;
}

As you can see Delta changes value, without me telling it to do so

I found a workaround, I tell the thread in its Run fnction to wait untill Delta is changed, and set my variables in game thread from the class calling this thread

And the performance increase was amazing btw, from a drop to bellow 5 fps to staying 100+ fps. Which I ussually have.