0

I've recently been looking into thread and thread management and there is something I find confusing this is What is the difference between a joined thread and a normal function call?

A thread that has been joined will block the calling thread, is this not the same functionality as a function call?

  • between the creation of the thread and the join, the calling thread can do other things. For a function call, that would not be the case. – Sander De Dycker Mar 04 '15 at 10:29

3 Answers3

2

it will block when you call .join. between the creation of the thread and thread.join you can invoke many function. diagrammatically it looks like this:

main-thread
|
new thread() ----
|               |
|               f'()
f1()            |
|               | 
f2()            | 
|               f''()
f3()            |
|               |
thread.join -----
David Haim
  • 25,446
  • 3
  • 44
  • 78
1
  1. With thread.join() you can have timed wait. So you can decide how
    long to wait which is not the case in normal function call.
  2. Some other thread can interrupt the waiting thread.
  3. thread.join() apparently looks like putting function executions in
    sequence but technically there are two different threads involved
    here. So thread local objects/resources are still not shared between them.
hemant1900
  • 1,226
  • 8
  • 9
0

If you are spinning off a thread only to instantly join it, you shouldn't be using threads.

The benefit of using threads is that you can let the thread do its job, go off and do some more processing, then call join when you actually need the result.

TartanLlama
  • 63,752
  • 13
  • 157
  • 193