Calin said:
I thought thread has a finish flag that you can check.
It has not, but there are many ways to communicate across multiple threads:
Atomics. E.g. thread A sets an atomic flag which other threads can check.
std::mutex can be used to define a critical code section which only one thread at a time can run.
std::condition_variable can be used to notify other threads, or to wake them up when they sleep but new work is ready, fopr example.
That's all i've personally used and needed so far. Idk about newer features such as std::future.
However, keep in mind that many of those language features are about creating new threads on demand.
For games this can be actually too slow, as creating threads is very expensive.
The better way is to create a pool of persistent worker threads just once at application launch, then using those same threads for all work that comes up. Beside the work management itself, this requires to set the threads to sleep if no work is pending, so they do not maximize CPU utilization just from constantly polling for pending work.
It's not easy to find related tutorials. The only one i know is this: https://wickedengine.net/2018/11/simple-job-system-using-standard-c/
This is not an ideal solution, but surely much better than creating threads on demand if you nedd many threads. Good enough for a start, if you're interested.
There are also related libraries, e.g. Intels TBB, but i have never used any of these.
I've heard future C++ standard may add those things, so maybe it's worth to wait.