Why we should use Join in threads?

Viewed 51954

I have 2 threads T1 and T2 ,both have different jobs so usually we prefer to accomplish this task by thread Joins.

But we can do this with out using join(). We can add T2 thread's code inside T1 thread. What difference does this make ?

10 Answers

All the parallel threads typically needs to join at some point in the code thereby allowing them to wait until all threads terminate. After this point typically the serial processing continues. This ensures proper synchronisation between peer threads so that subsequent serial code does not begin abruptly before all parallel threads complete the collective activity.

Related