Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why use join() ?

 
Faisal syed
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
join() Why use join() when we know our thread can finish only after the thread which we're joining? What purpose does this serve? What if I include the other thread's code in my own thread?
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example:

Say you have 75 mins of work and you work out that 25 mins and another 50 mins can be down in parallel (multithreaded) and the results combined so
you start the 50 min job in parallel (another thread) , do your 25 min work (main thread) and join to wait for the 50 min job to complete.

Total running time 50 mins , if you did all the work in one thread as you suggest 75 mins to do both sets (its faster).
 
suraj august
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main difference is if t1 thread wants to join t2 ,the time t2 is executing can be utilised by t1 also .
This cannot happen when you include t1 code in t2.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic