Search code examples
c++loopsjoinboostblocking

serial boost thread joins in loop vs parallel in main


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 joins called in main can run parallel while joins called in a loop in main cannot?


Solution

  • 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.