last day (14 days later) » 

7:36 PM
3
A: Joining a thread before program termination

ChristopheThere are two issues in your code: The join() on an active thread will wait that the thread is finished before continuing anything. So if you have no mechanism to to tell your threads to stop (e.g. a shared atomic variable), you'll wait forever. Your threadlist vector is inside the while l...

 
It's not UB, it will terminate if the vector goes out of scope before the threads it contains are joined. Apparently the code we've been shown isn't even close to the real code, since the real program isn't terminating.
 
Sorry, the vector inside the while loop was my mistake. It's actually a member of a class.
@JonathanWakely The real code functions the exact same way.
Unless I am understanding your answer incorrectly, that's what I'm trying to do - I need the main thread to wait for the most recent thread in the vector to finish.
 
You've just edited the code to move the vector outside the loop ... so it wasn't accurate then.
 
@JonathanWakely Correct - it was a simple mistake when I was writing the trivialized code.
 
"I need the main thread to wait for the most recent thread in the vector to finish." And that's what it's doing. So if it doesn't exit, then the thread hasn't finished.
 
7:39 PM
Hello. I'm sorry for the confusion - the thread that gets stuck is stuck for longer than it should be. Frankly, I'm stitching together multiple video clips into one file. join() blocks forever, which is much longer than any clip I'll ever make.
 
then the thread hasn't exited
 
The ones before it do.
 
your question only shows the calls to join() and asks why it doesn't join
the answer is that the thread hasn't finished
since you haven't shown what the threads are doing, you're asking "why does some code I haven't shown you not work correctly?"
obviously that's a silly question
and has nothing to do with thread::join()
 
I'm editing the question.
 
7:55 PM
I have edited the question.
 

last day (14 days later) »