Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to "join" a thread?

Tags:

c

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.

like image 789
i love stackoverflow Avatar asked Aug 30 '25 15:08

i love stackoverflow


1 Answers

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!

like image 62
Pavan Manjunath Avatar answered Sep 03 '25 02:09

Pavan Manjunath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!