神不在的星期二
展示这种机制的技术有些笨拙:join()大概是由主线程调用的。也可以由另一个线程调用它,但是会不必要地使该图复杂化。join调用应该放在主线程的轨道上,但是为了表达线程关系并使它尽可能简单,我选择将其放在子线程中。without join:+---+---+------------------ main-thread | | | +........... child-thread(short) +.................................. child-thread(long)with join+---+---+------------------***********+### main-thread | | | | +...........join() | child-thread(short) +......................join()...... child-thread(long)with join and daemon thread+-+--+---+------------------***********+### parent-thread | | | | | | +...........join() | child-thread(short) | +......................join()...... child-thread(long) +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, child-thread(long + daemonized)'-' main-thread/parent-thread/main-program execution'.' child-thread execution'#' optional parent-thread execution after join()-blocked parent-thread could continue'*' main-thread 'sleeping' in join-method, waiting for child-thread to finish',' daemonized thread - 'ignores' lifetime of other threads; terminates when main-programs exits; is normally meant for join-independent tasks因此,您看不到任何更改的原因是因为您的主线程在之后没有执行任何操作join。您可以说join(仅)与主线程的执行流程相关。例如,如果您要同时下载一堆页面以将它们串联成一个大页面,则可以使用线程开始并发下载,但是需要等到最后一页/线程完成后才能开始组装单个页面在很多。那是您使用的时间join()。