Are “data races” and “race condition” actually the same thing in context of concurrent programming

后端 未结 4 2029
一整个雨季
一整个雨季 2020-11-30 17:03

I often find these terms being used in context of concurrent programming . Are they the same thing or different ?

4条回答
  •  臣服心动
    2020-11-30 17:58

    No, they are different & neither of them is a subset of one or vice-versa.

    The term race condition is often confused with the related term data race, which arises when synchronization is not used to coordinate all access to a shared nonfinal field. You risk a data race whenever a thread writes a variable that might next be read by another thread or reads a variable that might have last been written by another thread if both threads do not use synchronization; code with data races has no useful defined semantics under the Java Memory Model. Not all race conditions are data races, and not all data races are race conditions, but they both can cause concurrent programs to fail in unpredictable ways.

    Taken from the excellent book - Java Concurrency in Practice by Joshua Bloch & Co.

提交回复
热议问题