In trying to understand this answer, I've found many similar questions and of course the docs but no explanation why.
Why is it that join
s called in main
can run parallel while join
s called in a loop in main
cannot?
Think of the sequence of events. It's the difference between
start thread 1
start thread 2
wait for thread 1 to finish
wait for thread 2 to finish
and
start thread 1
wait for thread 1 to finish
start thread 2
wait for thread 2 to finish
It should be obvious that, in the second case, the two threads never run at the same time.