Answer the question
In order to leave comments, you need to log in
How can a program wait for all std::thread threads to complete before exiting a function?
Good time!
I have 2 objects based on which, by composition, std::thread is encapsulated.
The program needs to start both threads and wait until they complete. When I execute:
somethread t1, t2;
t1.start();
t2.start();
t1.join();
t2.join();
// some work
exit();
Answer the question
In order to leave comments, you need to log in
then only t1 is attached to the main thread, and t2 by itself.
It is not at all clear what this phrase could mean?
No one "binds" to anyone, and pthraed_join() (which is what all your std::thread or boost::thread are built on) just waits for the joined (created in the PTHREAD_CREATE_JOINABLE state) thread to complete.
You just have a mistake in the architecture of a hypothetical application, and confusion in your head (regarding threads).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question