We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
AQS详解中,介绍AQS的成员变量state由 volatile 修饰,其中volatile的作用是使用volatile修饰保证线程可见性. 实际上使用 volatile 修饰状态变量不是为了利用 volatile 的内存可见性,因为这个状态变量只会被持有该状态变量的线程写入,只会被队列中该线程的后驱节点对应的线程读,而且后者会轮询读取。 但要实现一个可以在多线程程序中正确执行的锁,还需要解决重排序问题。主要是通过 volatile 的 Happens-Before(先行发生)规则来解决重排序问题。JMM 的 Happens-Before(先行发生)规则有一条针对 volatile 关键字的规则:“volatile 变量的写操作发生在该变量的后续读之前”。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
AQS详解中,介绍AQS的成员变量state由 volatile 修饰,其中volatile的作用是使用volatile修饰保证线程可见性.
实际上使用 volatile 修饰状态变量不是为了利用 volatile 的内存可见性,因为这个状态变量只会被持有该状态变量的线程写入,只会被队列中该线程的后驱节点对应的线程读,而且后者会轮询读取。
但要实现一个可以在多线程程序中正确执行的锁,还需要解决重排序问题。主要是通过 volatile 的 Happens-Before(先行发生)规则来解决重排序问题。JMM 的 Happens-Before(先行发生)规则有一条针对 volatile 关键字的规则:“volatile 变量的写操作发生在该变量的后续读之前”。
The text was updated successfully, but these errors were encountered: