First solution is
- create group of threads and push_bakc to vector
- join for all these threads
But sometimes is small interval between creating and destroying threads
I try use condition_variable with notify_one and wait
Is OK for one main thread and one working thread but when are two working thread it don't distinguish between threads.
> But sometimes is small interval between creating and destroying threads
Threads are pretty expensive things to use, so make sure you're getting value in the work done.
Consider creating a thread pool ( https://en.wikipedia.org/wiki/Thread_pool ), where you just feed the queue jobs to do, but the threads themselves persist.