For my class I’m supposed to find out what’s wrong with a piece of code, and the part I’m having trouble deciphering is
// joining a thread blocks until that thread finishes
a.join();
b.join();
Is joining a thread the same as locking a thread? Because I think the point of this assignment is you’re not supposed to leave threads unlocked.
This is how one thread waits for the completion of another thread!
A nice use case of
joinis – say for example themain()function/thread creates a thread and doesn’t wait ( usingjoin) for the created thread to complete and simply exits, then the newly created thread will also stop!Here is a nice explanation of Thread Management in general and Thread Join in particular! And here are some code snippets that show you some use cases of
joinand what happens when you don’t use it!