Thread.join() 和同步? [英] Thread.join() and synchronization?

查看:52
本文介绍了Thread.join() 和同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当线程被加入时,Thread.join() 是否与缓存刷新等完全同步?

Is Thread.join() a full synchronization with flushing of caches etc. when performed of the thread beeing joined?

推荐答案

认为你在问是否从线程 T1 调用 T2 上的 join,T1 中的代码读取 之后的数据join() 肯定会看到 T2 编写的更改.如果是这样,那么答案是肯定的,因为 JLS 17.4.4:

I think you're asking whether from thread T1 that calls join on T2, code in T1 reading data after the join() will definitely see changes written by T2. If that's the case, then the answer is yes, due to JLS 17.4.4:

线程 T1 中的最终操作与另一个线程 T2 中检测到 T1 已终止的任何操作同步.

The final action in a thread T1 synchronizes-with any action in another thread T2 that detects that T1 has terminated.

T2 可以通过调用 T1.isAlive() 或 T1.join() 来实现这一点.

JLS 17.4.5:

线程中的所有操作发生在之前任何其他线程从该线程上的join()成功返回.

All actions in a thread happen-before any other thread successfully returns from a join() on that thread.

这篇关于Thread.join() 和同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆