Does an object always see its latest internal state irrespective of thread?

前端 未结 3 1970
旧巷少年郎
旧巷少年郎 2021-02-20 00:15

Let\'s say I have a runnable with a simple integer count variable which is incremented every time runnable runs. One instance of this object is submitted to run periodically in

3条回答
  •  春和景丽
    2021-02-20 00:41

    No, this code is not thread-safe since there isn't any happens before relation between different threads accessing count.

提交回复
热议问题