On FRunnable and Rama's article.
I'm trying to build a motion control system using OpenCV, but since it's quite slow to use on the main thread I wanted to run the whole OpenCV code on a different thread. I've been following Rama's article about multithreading using FRunnable and FRunnableThread, but I must be doing something wrong because it looks like the thread I'm creating is running on the game thread. If I put an infinite loop inside the Run function of the Runnable class it freezes the whole game, if I put any code inside the Run function it first gets executed and then the game starts. I can't help but feel I'm missing something here.
I start the thread inside the player controller's BeginPlay.
And shutdown it inside the EndPlay
JoyInit does exactly what's in Rama's article
Anyone has any idea on what I'm doing wrong?
asked Dec 02 '17 at 12:13 AM in C++ Programming
I found the issue. From the FRunnable documentation page
And from the Init() declaration
I was calling the Runnable Init() function inside the static initialization function, which is inside the player controller. The player controller is on the main thread, therefore calling Init() inside the main thread will start the new thread inside the main thread. Basically I was not multi-threading at all. That's why my main thread was stalling.
The Init() function doesn't need to be called manually because it's already called inside the FRunnableThread::Run() function. And in that case, it's already on a new thread. That's why deleting Init() solved my issue.
At least that's what I think was going on. Hope I'm not mistaken and hope this helps other people! :)
Follow this question
Once you sign in you will be able to subscribe for any updates here