Start/stop group of threads

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.
Before you start adding threads, you need a plan!

Figure out who owns what and for how long, and the rules you use to hand over responsibility for data from one thread to another.

Expect plenty of these in your future if you rush this.
https://stackoverflow.com/questions/34510/what-is-a-race-condition

> 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.

As an alternative, OpenMP.
Reference: https://www.openmp.org/resources/refguides/
Examples: https://computing.llnl.gov/tutorials/openMP/exercise.html

Registered users can post here. Sign in or register to post.