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 join
is - say for example the main()
function/thread creates a thread and doesn't wait ( using join
) 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 join
and what happens when you don't use it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With