It sounds to me more like you’re new to C++ programming in general.
Unreal manages the lifetime of UObjects. Typically, you will make your UObject and Actor so it’s easy to manage from the game code.
You should implement an Actor (or other UObject) that starts a thread. The function for that thread should be a (renamed) version of your main() function.
However, the C++ code you show is 100% incompatible with any real-time game that uses a graphical UI, so I think you have a fair amount of things to learn before you can actually get where you want to go.
Things to learn include:
- asynchronous programming
- concurrent programming
- blocking versus non-blocking code
- event-based and reactive programming
- GUI-based user interaction
- component based architecture (delegation versus inheritance)
These are just general patterns that happen in pretty much all actual shipping software systems.
Once you actually understand and use these concepts, merging them into the Unreal Engine will be pretty easy, because the Unreal Engine APIs provide good implementations and places to hook into for all of these things.