同步块中的读取障碍和写入障碍是什么 [英] what are read barriers and write barriers in synchronized block

查看:212
本文介绍了同步块中的读取障碍和写入障碍是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究同步和volatile变量如何在java中工作,我遇到了一个名为read and write barrier的概念。任何人都可以帮我理解这个术语的含义

I am looking into how a synchronized and volatile variable works in java and i came across a concept called read and write barrier . Can anyone help me to understand the meaning of this terms

推荐答案

(上面的答案都很完整),我只是想展示一下简单方案的概念

( the answers above are quite complete), I just want to demonstrate the concept with a simple scheme

 Thread 1                                                             Thread 2


   |          
   |                                                                      
   |                                                                      |
   |                                                                      |
   |  Everything Thread 1                                                 |
   |   wrote before here                                                  |
   |                                                                      |
   |                                                                      |
    _ _ _ _ _ _ _ _ _ _                                                   |
      ( write  barrier)         (happens before)         (read barrier)   |
   |                                                     _ _  _ _ _ _ _ _  
   |
   |                                                   is guaranteed      |
   |                                                  to be visible to    |
   |                                                  Thread 2            |
   |                                                                      |

这篇关于同步块中的读取障碍和写入障碍是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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