Mar-19-2019, 08:23 PM
(Mar-19-2019, 07:59 PM)nilamo Wrote: Thread.join() will stop the current thread, until the referenced thread has completed. In your example,t1.join()
would stop the main thread, while botht1
andt2
continue running. Oncet1
completes, the main thread would resume. The very next line,t2.join()
, would again halt the main thread untilt2
had completed. At that point, you had already guaranteed thatt1
had completed, so the only running thread would bet2
.
Oncet2
completes, the main thread would resume. At the next instruction,print("bye")
, the main thread is the only thread still running.
thanks nilamo,
that makes sense, but lets suppose t2 somehow finished before t1, t1.join() finishes now the next line will be t2.join() but t2 has already finished running also, what would happen?
thanks