serial boost thread joins in loop vs parallel in m

2019-09-16 10:52发布

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?

1条回答
▲ chillily
2楼-- · 2019-09-16 11:25

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.

查看更多
登录 后发表回答