【翻譯六】什麼是未正確同步?

What do you mean by 「incorrectly synchronized」?

Incorrectly synchronized code can mean different things to different people. When we talk about incorrectly synchronized code in the context of the Java Memory Model, we mean any code where線程

不一樣的人會寫出不一樣的bug,也會出現各類不一樣的同步問題,但對於JMM,如下狀況就是未正確同步的code

  1. there is a write of a variable by one thread,排序

  2. there is a read of the same variable by another thread and同步

  3. the write and read are not ordered by synchronizationit

  4. 一條線程正在寫入一個變量io

  5. 另外一條線程正在讀取這個變量thread

  6. 這兩個線程的讀寫沒有經過同步進行強制排序變量

When these rules are violated, we say we have a data race on that variable. A program with a data race is an incorrectly synchronized program.bug

這種狀況下,咱們就稱之爲這個變量存在數據競爭。有數據競爭的程序,就是一個未正確同步的程序。程序

相關文章
相關標籤/搜索