Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在试图理解这个答案时,我发现了许多类似的问题,当然还有文档,但没有解释原因。
为什么join调用的 smain可以并行运行,而join循环调用的 smain不能?
join
main
想想事件的顺序。这是之间的区别
start thread 1 start thread 2 wait for thread 1 to finish wait for thread 2 to finish
和
start thread 1 wait for thread 1 to finish start thread 2 wait for thread 2 to finish
很明显,在第二种情况下,两个线程永远不会同时运行。